Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
patch-select: Default to JSON output and remove option
Erik Kundt committed 2 years ago
commit 653b1c57f7610e0985f4990488e89cbb705f5a9f
parent d7a3265df010d51e1d6d3849ad14c66dd452699e
1 file changed +4 -21
modified bin/commands/patch.rs
@@ -45,14 +45,12 @@ Select options

Other options

-
    --json              Output is JSON (default: false)
    --help              Print help
"#,
};

pub struct Options {
    op: Operation,
-
    json: bool,
}

pub enum Operation {
@@ -76,7 +74,6 @@ impl Args for Options {

        let mut parser = lexopt::Parser::from_args(args);
        let mut op: Option<OperationName> = None;
-
        let mut json = false;
        let mut select_opts = SelectOptions::default();

        while let Some(arg) = parser.next()? {
@@ -84,9 +81,6 @@ impl Args for Options {
                Long("help") | Short('h') => {
                    return Err(Error::Help.into());
                }
-
                Long("json") | Short('j') => {
-
                    json = true;
-
                }

                // select options.
                Long("mode") | Short('m') if op == Some(OperationName::Select) => {
@@ -134,7 +128,7 @@ impl Args for Options {
        let op = match op.ok_or_else(|| anyhow!("an operation must be provided"))? {
            OperationName::Select => Operation::Select { opts: select_opts },
        };
-
        Ok((Options { op, json }, vec![]))
+
        Ok((Options { op }, vec![]))
    }
}

@@ -152,20 +146,9 @@ pub fn run(options: Options, _ctx: impl terminal::Context) -> anyhow::Result<()>
            let mut app = select::App::new(context, opts.mode.clone(), opts.filter.clone());
            let output = Window::default().run(&mut app, 1000 / FPS)?;

-
            let output = if options.json {
-
                output
-
                    .map(|o| serde_json::to_string(&o).unwrap_or_default())
-
                    .unwrap_or_default()
-
            } else {
-
                match options.op {
-
                    Operation::Select { ref opts } => match &opts.mode {
-
                        select::Mode::Id => output.map(|o| format!("{}", o)).unwrap_or_default(),
-
                        select::Mode::Operation => output
-
                            .map(|o| format!("rad patch {}", o))
-
                            .unwrap_or_default(),
-
                    },
-
                }
-
            };
+
            let output = output
+
                .map(|o| serde_json::to_string(&o).unwrap_or_default())
+
                .unwrap_or_default();

            eprint!("{output}");
        }