feat(config): implement config init/get/set/path commands

This commit is contained in:
Ciphercat 2026-03-05 18:28:24 +00:00
commit d2fa081266
4 changed files with 134 additions and 7 deletions

View file

@ -1,5 +1,8 @@
use clap::{Args, Subcommand};
use crate::config::{config_path, ensure_default_config, get_config_value, set_config_value};
use crate::error::IdxError;
#[derive(Debug, Args)]
pub struct ConfigCmd {
#[command(subcommand)]
@ -13,3 +16,25 @@ pub enum ConfigSubcommand {
Set { key: String, value: String },
Path,
}
pub fn handle(cmd: &ConfigCmd) -> Result<(), IdxError> {
match &cmd.command {
ConfigSubcommand::Init => {
let path = ensure_default_config()?;
println!("{}", path.display());
}
ConfigSubcommand::Get { key } => {
let value = get_config_value(key)?
.ok_or_else(|| IdxError::ConfigError(format!("key not found: {key}")))?;
println!("{value}");
}
ConfigSubcommand::Set { key, value } => {
set_config_value(key, value)?;
println!("ok");
}
ConfigSubcommand::Path => {
println!("{}", config_path()?.display());
}
}
Ok(())
}