use std::path::{Path, PathBuf};
use clap::{ArgAction, Args, Subcommand, ValueHint};
use super::ICP_ENVIRONMENT_ENV;
#[derive(Debug, Subcommand)]
pub(crate) enum ConfigCommand {
Init(ConfigInitArgs),
Show(ConfigArgs),
Check(ConfigArgs),
}
#[derive(Args, Clone, Debug)]
pub(crate) struct ConfigArgs {
#[arg(long, value_name = "DIR", value_hint = ValueHint::DirPath)]
start_dir: Option<PathBuf>,
#[arg(short, long, env = ICP_ENVIRONMENT_ENV, value_name = "ENV")]
environment: Option<String>,
}
impl ConfigArgs {
pub(crate) fn environment(&self) -> Option<&str> {
self.environment.as_deref()
}
pub(crate) fn start_dir(&self) -> Option<&Path> {
self.start_dir.as_deref()
}
}
#[derive(Args, Clone, Debug)]
pub(crate) struct ConfigInitArgs {
#[arg(long, value_name = "DIR", value_hint = ValueHint::DirPath)]
start_dir: Option<PathBuf>,
#[arg(short, long, value_name = "CANISTER")]
canister: String,
#[command(flatten)]
surfaces: ConfigInitSurfaceArgs,
#[arg(long)]
force: bool,
}
#[derive(Args, Clone, Debug)]
#[expect(
clippy::struct_excessive_bools,
reason = "clap flag bags intentionally mirror independent command-line switches"
)]
struct ConfigInitSurfaceArgs {
#[arg(long)]
ddl: bool,
#[arg(long)]
fixtures: bool,
#[arg(long)]
metrics: bool,
#[arg(long = "metrics-reset")]
metrics_reset: bool,
#[arg(long)]
snapshot: bool,
#[arg(long)]
schema: bool,
#[arg(long)]
all: bool,
#[arg(long = "no-readonly", action = ArgAction::SetFalse, default_value_t = true)]
readonly: bool,
}
impl ConfigInitArgs {
pub(crate) fn start_dir(&self) -> Option<&Path> {
self.start_dir.as_deref()
}
pub(crate) const fn canister_name(&self) -> &str {
self.canister.as_str()
}
pub(crate) const fn readonly(&self) -> bool {
self.surfaces.readonly
}
pub(crate) const fn ddl(&self) -> bool {
self.surfaces.ddl()
}
pub(crate) const fn fixtures(&self) -> bool {
self.surfaces.fixtures()
}
pub(crate) const fn metrics(&self) -> bool {
self.surfaces.metrics()
}
pub(crate) const fn metrics_reset(&self) -> bool {
self.surfaces.metrics_reset()
}
pub(crate) const fn snapshot(&self) -> bool {
self.surfaces.snapshot()
}
pub(crate) const fn schema(&self) -> bool {
self.surfaces.schema()
}
pub(crate) const fn force(&self) -> bool {
self.force
}
}
impl ConfigInitSurfaceArgs {
const fn ddl(&self) -> bool {
self.surface_enabled(self.ddl)
}
const fn fixtures(&self) -> bool {
self.surface_enabled(self.fixtures)
}
const fn metrics(&self) -> bool {
self.surface_enabled(self.metrics)
}
const fn metrics_reset(&self) -> bool {
self.surface_enabled(self.metrics_reset)
}
const fn snapshot(&self) -> bool {
self.surface_enabled(self.snapshot)
}
const fn schema(&self) -> bool {
self.surface_enabled(self.schema)
}
const fn surface_enabled(&self, enabled: bool) -> bool {
enabled || self.all
}
}