use anyhow::Result;
use clap::{Args, Subcommand};
use crate::db::config::Config;
#[derive(Args)]
pub struct ConfigArgs {
#[command(subcommand)]
command: ConfigCommand,
}
#[derive(Subcommand)]
enum ConfigCommand {
Set {
key: String,
value: String,
},
Get {
key: String,
},
List,
}
impl ConfigArgs {
pub fn run(self) -> Result<()> {
let mut config = Config::load()?;
match self.command {
ConfigCommand::Set { key, value } => {
config.set(&key, &value)?;
config.save()?;
println!("Set {key} = {value}");
}
ConfigCommand::Get { key } => match config.get(&key) {
Some(value) => println!("{value}"),
None => eprintln!("No value set for: {key}"),
},
ConfigCommand::List => {
for (key, value) in config.entries() {
println!("{key} = {value}");
}
}
}
Ok(())
}
}