Patchwork D8956: rhg: print error message when argument parsing fails

login
register
mail settings
Submitter phabricator
Date Aug. 26, 2020, 1:24 p.m.
Message ID <differential-rev-PHID-DREV-koxkpcno43t7366ndltj-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47057/
State Superseded
Headers show

Comments

phabricator - Aug. 26, 2020, 1:24 p.m.
acezar created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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




To: acezar, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

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,12 @@ 
 
         stderr.flush().or_else(handle_stderr_error)
     }
+
+    /// Write string line to stderr
+    pub fn writeln_stderr_str(&self, s: &str) -> Result<(), UiError> {
+        eprintln!("{}", s);
+        Ok(())
+    }
 }
 
 /// 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)
     });