changeset 45440:a6a000ab135b

rhg: print error message when argument parsing fails Differential Revision: https://phab.mercurial-scm.org/D8956
author Antoine Cezar <antoine.cezar@octobus.net>
date Mon, 17 Aug 2020 16:55:43 +0200
parents fbc373b7cbc3
children 3d9f1dfc52c2
files rust/rhg/src/main.rs rust/rhg/src/ui.rs tests/test-rhg.t
diffstat 3 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rust/rhg/src/main.rs	Thu Aug 13 16:36:42 2020 +0200
+++ b/rust/rhg/src/main.rs	Mon Aug 17 16:55:43 2020 +0200
@@ -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)
     });
 
--- a/rust/rhg/src/ui.rs	Thu Aug 13 16:36:42 2020 +0200
+++ b/rust/rhg/src/ui.rs	Mon Aug 17 16:55:43 2020 +0200
@@ -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.
--- a/tests/test-rhg.t	Thu Aug 13 16:36:42 2020 +0200
+++ b/tests/test-rhg.t	Mon Aug 17 16:55:43 2020 +0200
@@ -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 <SUBCOMMAND>
+  
+  For more information try --help
   [252]
 
 Finding root