diff --git a/radicle-cli/src/commands/patch/list.rs b/radicle-cli/src/commands/patch/list.rs index ee28cd52..a0450d1c 100644 --- a/radicle-cli/src/commands/patch/list.rs +++ b/radicle-cli/src/commands/patch/list.rs @@ -76,10 +76,7 @@ pub fn run( if !errors.is_empty() { for (title, id, error) in errors { - term::error(format!( - "{} Patch {title:?} ({id}) failed to load: {error}", - term::format::negative("Error:") - )); + term::error(format!("patch {title:?} ({id}) failed to load: {error}",)); } } diff --git a/radicle-cli/src/commands/publish.rs b/radicle-cli/src/commands/publish.rs index 818c364f..6820ea80 100644 --- a/radicle-cli/src/commands/publish.rs +++ b/radicle-cli/src/commands/publish.rs @@ -110,9 +110,9 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { if !validations.is_empty() { for err in validations { - term::error(format!("Error: validation error {err}")); + term::error(format!("validation error: {err}")); } - anyhow::bail!("fatal error: repository storage is corrupt"); + anyhow::bail!("fatal: repository storage is corrupt"); } term::success!( diff --git a/radicle-cli/src/main.rs b/radicle-cli/src/main.rs index 25d991c1..6010f8aa 100644 --- a/radicle-cli/src/main.rs +++ b/radicle-cli/src/main.rs @@ -25,7 +25,7 @@ fn main() { Ok(_) => process::exit(0), Err(err) => { if let Some(err) = err { - term::error(format!("Error: rad: {err}")); + term::error(format!("rad: {err}")); } process::exit(1); } @@ -277,7 +277,7 @@ fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option> rad_remote::run, args.to_vec(), ), - _ => { + other => { let exe = format!("{NAME}-{exe}"); let status = process::Command::new(exe.clone()).args(args).status(); @@ -289,7 +289,9 @@ fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option> } Err(err) => { if let ErrorKind::NotFound = err.kind() { - return Err(Some(anyhow!("command `{}` not found", exe))); + return Err(Some(anyhow!( + "`{other}` is not a command. See `rad --help` for a list of commands.", + ))); } else { return Err(Some(err.into())); } diff --git a/radicle-cli/src/terminal.rs b/radicle-cli/src/terminal.rs index 86e5664d..21ab8b7a 100644 --- a/radicle-cli/src/terminal.rs +++ b/radicle-cli/src/terminal.rs @@ -86,7 +86,7 @@ where } Some(Error::HelpManual) => { let Ok(status) = term::manual(help.name) else { - perror(help.name, "failed to load manual page"); + io::error(format!("rad {}: failed to load manual page", help.name)); process::exit(1); }; process::exit(status.code().unwrap_or(0)); @@ -98,10 +98,10 @@ where Some(Error::WithHint { hint, .. }) => Some(hint), None => None, }; - perror(help.name, &err); + io::error(format!("rad {}: {err}", help.name)); if let Some(hint) = hint { - eprintln!("{}", Paint::yellow(hint)); + io::hint(hint); } process::exit(1); } @@ -128,23 +128,15 @@ pub fn profile() -> Result { } } -pub fn perror(name: &str, err: impl std::fmt::Display) { - eprintln!( - "{ERROR_PREFIX} {} rad {}: {err}", - Paint::red("Error:"), - name, - ); -} - pub fn fail(_name: &str, error: &anyhow::Error) { let err = error.to_string(); let err = err.trim_end(); for line in err.lines() { - println!("{ERROR_PREFIX} {} {line}", Paint::red("Error:")); + io::error(line); } if let Some(Error::WithHint { hint, .. }) = error.downcast_ref::() { - println!("{ERROR_HINT_PREFIX} {}", Paint::yellow(hint)); + io::hint(hint); } } diff --git a/radicle-term/src/io.rs b/radicle-term/src/io.rs index 1f8f4fc4..24844839 100644 --- a/radicle-term/src/io.rs +++ b/radicle-term/src/io.rs @@ -174,7 +174,11 @@ pub fn warning(warning: impl fmt::Display) { } pub fn error(error: impl fmt::Display) { - println!("{ERROR_PREFIX} {error}"); + println!("{ERROR_PREFIX} {} {error}", Paint::red("Error:")); +} + +pub fn hint(hint: impl fmt::Display) { + println!("{ERROR_HINT_PREFIX} {}", Paint::yellow(hint)); } pub fn ask(prompt: D, default: bool) -> bool {