Skip to main content

commit_wizard/cli/cmd/config/
mod.rs

1use clap::{Args as ClapArgs, Subcommand};
2
3use crate::{
4    cli::CliResult,
5    core::{configs, context::Context},
6};
7
8#[derive(Debug, Clone, ClapArgs)]
9#[command(about = "Inspect and manage Commit Wizard configuration")]
10pub struct Args {
11    /// Edit the global config instead of project config
12    #[arg(short = 'g', long = "global", conflicts_with = "config")]
13    pub global: bool,
14    #[command(subcommand)]
15    pub subcommand: ConfigSubcommand,
16}
17
18#[derive(Debug, Clone, Subcommand)]
19pub enum ConfigSubcommand {
20    /// Show the config file path that CW will target
21    Path,
22    /// Show the active configuration
23    Show {
24        // Show effective configuration (merging global and local)
25        // #[arg(long)]
26        // effective: bool,
27    },
28    /// Get a config value
29    Get {
30        /// Config key to retrieve
31        key: String,
32    },
33    /// Set a config value
34    Set {
35        /// Config key to set
36        key: String,
37        /// Value to set
38        value: String,
39    },
40    /// Unset a config value
41    Unset {
42        /// Config key to unset
43        key: String,
44    },
45    // /// Open an interactive editor for the config (guided prompts)
46    // Edit,
47}
48
49pub async fn run(ctx: &Context, args: Args) -> CliResult<()> {
50    let global = args.global;
51    match args.subcommand {
52        ConfigSubcommand::Path => configs::config_path(ctx, global),
53        ConfigSubcommand::Show {} => configs::config_show(ctx, global),
54        ConfigSubcommand::Get { key } => configs::config_get(ctx, &key, global),
55        ConfigSubcommand::Set { key, value, .. } => configs::config_set(ctx, &key, &value, global),
56        ConfigSubcommand::Unset { key } => configs::config_unset(ctx, &key, global),
57    }
58}