Radish alpha
r
rad:z39mP9rQAaGmERfUMPULfPUi473tY
Radicle terminal user interface
Radicle
Git
bin: Handle `no-forward` option in main entry
Erik Kundt committed 1 year ago
commit cd55f03965004bcbbc0205aee2b3142d15e6bbd5
parent 976346c
1 file changed +24 -6
modified bin/main.rs
@@ -45,7 +45,7 @@ fn main() {
        Ok(_) => process::exit(0),
        Err(err) => {
            if let Some(err) = err {
-
                term::error(format!("rad: {err}"));
+
                term::error(format!("rad-tui: {err}"));
            }
            process::exit(1);
        }
@@ -57,9 +57,13 @@ fn parse_args() -> anyhow::Result<Command> {

    let mut parser = lexopt::Parser::from_env();
    let mut command = None;
+
    let mut forward = true;

    while let Some(arg) = parser.next()? {
        match arg {
+
            Long("no-forward") => {
+
                forward = false;
+
            }
            Long("help") | Short('h') => {
                command = Some(Command::Help);
            }
@@ -67,16 +71,30 @@ fn parse_args() -> anyhow::Result<Command> {
                command = Some(Command::Version);
            }
            Value(val) if command.is_none() => {
-
                let args = iter::once(val)
-
                    .chain(iter::from_fn(|| parser.value().ok()))
-
                    .collect();
-

-
                command = Some(Command::Other(args))
+
                command = match val.to_string_lossy().as_ref() {
+
                    "help" => Some(Command::Help),
+
                    "version" => Some(Command::Version),
+
                    _ => {
+
                        let args = iter::once(val)
+
                            .chain(iter::from_fn(|| parser.value().ok()))
+
                            .collect();
+

+
                        Some(Command::Other(args))
+
                    }
+
                }
            }
            _ => return Err(anyhow::anyhow!(arg.unexpected())),
        }
    }

+
    if forward {
+
        command = match command {
+
            Some(Command::Help) => Some(Command::Other(vec!["help".into()])),
+
            Some(Command::Version) => Some(Command::Other(vec!["version".into()])),
+
            other => other,
+
        };
+
    }
+

    Ok(command.unwrap_or_else(|| Command::Other(vec![])))
}