Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: refactor
✗ CI failure Fintan Halpenny committed 6 months ago
commit ff000c3c487a03aa5a0fd65760eadf696449a753
parent 000964b5d2878e7ddb0ff1ecb6f0902b1260630f
1 failed 1 pending (2 total) View logs
1 file changed +13 -31
modified crates/radicle-cli/src/commands/config.rs
@@ -11,19 +11,16 @@ use radicle::profile::{config, Config, ConfigPath, RawConfig};
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(|| {
@@ -31,33 +28,23 @@ pub fn run(options: Args, ctx: impl term::Context) -> anyhow::Result<()> {
            })?;
            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());
            }
@@ -67,18 +54,13 @@ pub fn run(options: Args, ctx: impl term::Context) -> anyhow::Result<()> {
                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();
        }