[Updated] D8956: rhg: print error message when argument parsing fails

acezar (Antoine Cezar) phabricator at mercurial-scm.org
Mon Aug 31 15:04:22 UTC 2020


acezar marked an inline comment as done.
acezar updated this revision to Diff 22495.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8956?vs=22456&id=22495

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8956/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8956

AFFECTED FILES
  rust/rhg/src/main.rs
  rust/rhg/src/ui.rs
  tests/test-rhg.t

CHANGE DETAILS

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 <SUBCOMMAND>
+  
+  For more information try --help
   [252]
 
 Finding root
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/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)
     });
 



To: acezar, #hg-reviewers, marmoute
Cc: Alphare, marmoute, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200831/6268db1a/attachment-0002.html>


More information about the Mercurial-patches mailing list