use clap::{Args as ClapArgs, Subcommand};
use crate::{
cli::CliResult,
core::{configs, context::Context},
};
#[derive(Debug, Clone, ClapArgs)]
#[command(about = "Inspect and manage Commit Wizard configuration")]
pub struct Args {
#[arg(short = 'g', long = "global", global = true, conflicts_with = "config")]
pub global: bool,
#[command(subcommand)]
pub subcommand: ConfigSubcommand,
}
#[derive(Debug, Clone, Subcommand)]
pub enum ConfigSubcommand {
Path,
Show {
},
Get {
key: String,
},
Set {
key: String,
value: String,
},
Unset {
key: String,
},
Edit,
List {
#[arg(long)]
effective: bool,
prefix: Option<String>,
},
}
pub async fn run(ctx: &Context, args: Args) -> CliResult<()> {
let global = args.global;
match args.subcommand {
ConfigSubcommand::Path => configs::config_path(ctx, global),
ConfigSubcommand::Edit => configs::wizard::edit_config(ctx, global),
ConfigSubcommand::List { effective, prefix } => {
configs::config_list(ctx, global, effective, prefix)
}
ConfigSubcommand::Show {} => configs::config_show(ctx, global),
ConfigSubcommand::Get { key } => configs::config_get(ctx, &key, global),
ConfigSubcommand::Set { key, value, .. } => configs::config_set(ctx, &key, &value, global),
ConfigSubcommand::Unset { key } => configs::config_unset(ctx, &key, global),
}
}