diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs --- a/rust/rhg/src/main.rs +++ b/rust/rhg/src/main.rs @@ -21,7 +21,8 @@ SubCommand::with_name("files").about(commands::files::HELP_TEXT), ); - let matches = app.clone().get_matches_safe().unwrap_or_else(|_| { + let matches = app.clone().get_matches_safe().unwrap_or_else(|err| { + let _ = ui::Ui::new().writeln_stderr_str(&err.message); std::process::exit(exitcode::UNIMPLEMENTED_COMMAND) }); diff --git a/rust/rhg/src/ui.rs b/rust/rhg/src/ui.rs --- a/rust/rhg/src/ui.rs +++ b/rust/rhg/src/ui.rs @@ -47,6 +47,11 @@ stderr.flush().or_else(handle_stderr_error) } + + /// Write string line to stderr + pub fn writeln_stderr_str(&self, s: &str) -> Result<(), UiError> { + self.write_stderr(&format!("{}\n", s).as_bytes()) + } } /// A buffered stdout writer for faster batch printing operations. diff --git a/tests/test-rhg.t b/tests/test-rhg.t --- a/tests/test-rhg.t +++ b/tests/test-rhg.t @@ -12,6 +12,12 @@ Unimplemented command $ rhg unimplemented-command + error: Found argument 'unimplemented-command' which wasn't expected, or isn't valid in this context + + USAGE: + rhg + + For more information try --help [252] Finding root