mirror of
https://github.com/0xrsydn/idx-cli.git
synced 2026-11-07 09:45:36 +00:00
feat(config): implement config init/get/set/path commands
This commit is contained in:
parent
2b5a1b28de
commit
d2fa081266
4 changed files with 134 additions and 7 deletions
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue