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