Skip to main content

codetether_agent/cli/
config.rs

1//! Configuration management commands
2
3use super::ConfigArgs;
4use crate::config::Config;
5use anyhow::Result;
6
7pub async fn execute(args: ConfigArgs) -> Result<()> {
8    if args.show {
9        let config = Config::load().await?;
10        println!("{}", toml::to_string_pretty(&config)?);
11        return Ok(());
12    }
13
14    if args.init {
15        Config::init_default().await?;
16        println!("Configuration initialized");
17        return Ok(());
18    }
19
20    if let Some(kv) = args.set {
21        let parts: Vec<&str> = kv.splitn(2, '=').collect();
22        if parts.len() != 2 {
23            anyhow::bail!("Invalid format. Use: --set key=value");
24        }
25        Config::set(parts[0], parts[1]).await?;
26        println!("Set {} = {}", parts[0], parts[1]);
27        if parts[0] == "telemetry.crash_reporting" {
28            if matches!(
29                parts[1].trim().to_ascii_lowercase().as_str(),
30                "1" | "true" | "yes" | "on"
31            ) {
32                println!(
33                    "Crash reporting enabled (opt-in). Panic reports include stack traces and runtime metadata. Disable with: codetether config --set telemetry.crash_reporting=false"
34                );
35            } else if matches!(
36                parts[1].trim().to_ascii_lowercase().as_str(),
37                "0" | "false" | "no" | "off"
38            ) {
39                println!("Crash reporting disabled.");
40            }
41        }
42        return Ok(());
43    }
44
45    // Default: show help
46    println!("Use --show, --init, or --set key=value");
47    Ok(())
48}