doum_cli/cli/
config.rs

1use crate::cli::args::ConfigAction;
2use crate::core::ConfigManager;
3use anyhow::Result;
4
5pub fn handle_config_command(action: Option<ConfigAction>) -> Result<()> {
6    // if no action is provided, default to Show
7    let action = action.unwrap_or(ConfigAction::Show);
8
9    match action {
10        ConfigAction::Show => {
11            let config_path = ConfigManager::get_config_path()?;
12            let toml_str = ConfigManager::get_all_as_toml()?;
13            println!("Config file location: {}\n", config_path.display());
14            println!("{}", toml_str);
15            Ok(())
16        }
17        ConfigAction::Reset => {
18            ConfigManager::reset()?;
19            println!("✅ Configuration reset to default");
20            Ok(())
21        }
22        ConfigAction::Set { key, value } => {
23            ConfigManager::set_value(&key, &value)?;
24            println!("✅ Config {} = {}", key, value);
25            Ok(())
26        }
27        ConfigAction::Get { key } => {
28            let value = ConfigManager::get_value(&key)?;
29            println!("{}", value);
30            Ok(())
31        }
32        ConfigAction::Unset { key } => {
33            ConfigManager::unset_value(&key)?;
34            println!("✅ Config {} reset to default", key);
35            Ok(())
36        }
37    }
38}