| |
use crate::terminal as term;
|
| |
use crate::terminal::Element as _;
|
| |
|
| - |
pub fn run(options: Args, ctx: impl term::Context) -> anyhow::Result<()> {
|
| + |
pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
|
| |
let home = ctx.home()?;
|
| |
let path = home.config();
|
| + |
let command = args.command.unwrap_or(Command::Show);
|
| |
|
| - |
match options {
|
| - |
Args {
|
| - |
command: Some(Command::Schema),
|
| - |
} => {
|
| - |
term::json::to_pretty(&schemars::schema_for!(Config), path.as_path())?.print();
|
| + |
match command {
|
| + |
Command::Schema => {
|
| + |
term::json::to_pretty(&schemars::schema_for!(Config), path.as_path())?.print()
|
| |
}
|
| - |
Args {
|
| - |
command: Some(Command::Get { key }),
|
| - |
} => {
|
| + |
Command::Get { key } => {
|
| |
let mut temp_config = RawConfig::from_file(&path)?;
|
| |
let key: ConfigPath = key.into();
|
| |
let value = temp_config.get_mut(&key).ok_or_else(|| {
|
| |
})?;
|
| |
print_value(value)?;
|
| |
}
|
| - |
Args {
|
| - |
command: Some(Command::Set { key, value }),
|
| - |
} => {
|
| + |
Command::Set { key, value } => {
|
| |
let value = modify(path, |tmp| tmp.set(&key.into(), value.into()))?;
|
| |
print_value(&value)?;
|
| |
}
|
| - |
Args {
|
| - |
command: Some(Command::Push { key, value }),
|
| - |
} => {
|
| + |
Command::Push { key, value } => {
|
| |
let value = modify(path, |tmp| tmp.push(&key.into(), value.into()))?;
|
| |
print_value(&value)?;
|
| |
}
|
| - |
Args {
|
| - |
command: Some(Command::Remove { key, value }),
|
| - |
} => {
|
| + |
Command::Remove { key, value } => {
|
| |
let value = modify(path, |tmp| tmp.remove(&key.into(), value.into()))?;
|
| |
print_value(&value)?;
|
| |
}
|
| - |
Args {
|
| - |
command: Some(Command::Unset { key }),
|
| - |
} => {
|
| + |
Command::Unset { key } => {
|
| |
let value = modify(path, |tmp| tmp.unset(&key.into()))?;
|
| |
print_value(&value)?;
|
| |
}
|
| - |
Args {
|
| - |
command: Some(Command::Init { alias }),
|
| - |
} => {
|
| + |
Command::Init { alias } => {
|
| |
if path.try_exists()? {
|
| |
anyhow::bail!("configuration file already exists at `{}`", path.display());
|
| |
}
|
| |
path.display()
|
| |
);
|
| |
}
|
| - |
Args {
|
| - |
command: Some(Command::Edit),
|
| - |
} => match term::editor::Editor::new(&path)?.extension("json").edit()? {
|
| + |
Command::Edit => match term::editor::Editor::new(&path)?.extension("json").edit()? {
|
| |
Some(_) => {
|
| |
term::success!("Successfully made changes to the configuration at {path:?}")
|
| |
}
|
| |
None => term::info!("No changes were made to the configuration at {path:?}"),
|
| |
},
|
| - |
Args { command: None }
|
| - |
| Args {
|
| - |
command: Some(Command::Show),
|
| - |
} => {
|
| + |
Command::Show => {
|
| |
let profile = ctx.profile()?;
|
| |
term::json::to_pretty(&profile.config, path.as_path())?.print();
|
| |
}
|