##// END OF EJS Templates
rhg: Remove error message on unsupported CLI arguments...
Simon Sapin -
r47333:21d3b40b default
parent child Browse files
Show More
@@ -33,6 +33,14 b' impl CommandError {'
33 33 }
34 34 }
35 35
36 /// For now we don’t differenciate between invalid CLI args and valid for `hg`
37 /// but not supported yet by `rhg`.
38 impl From<clap::Error> for CommandError {
39 fn from(_: clap::Error) -> Self {
40 CommandError::Unimplemented
41 }
42 }
43
36 44 impl From<HgError> for CommandError {
37 45 fn from(error: HgError) -> Self {
38 46 match error {
@@ -33,7 +33,7 b" fn add_global_args<'a, 'b>(app: App<'a, "
33 33 )
34 34 }
35 35
36 fn main() {
36 fn main_with_result(ui: &ui::Ui) -> Result<(), CommandError> {
37 37 env_logger::init();
38 38 let app = App::new("rhg")
39 39 .setting(AppSettings::AllowInvalidUtf8)
@@ -43,12 +43,7 b' fn main() {'
43 43 let app = add_global_args(app);
44 44 let app = add_subcommand_args(app);
45 45
46 let ui = ui::Ui::new();
47
48 let matches = app.clone().get_matches_safe().unwrap_or_else(|err| {
49 let _ = ui.writeln_stderr_str(&err.message);
50 std::process::exit(exitcode::UNIMPLEMENTED)
51 });
46 let matches = app.clone().get_matches_safe()?;
52 47
53 48 let (subcommand_name, subcommand_matches) = matches.subcommand();
54 49 let run = subcommand_run_fn(subcommand_name)
@@ -69,16 +64,18 b' fn main() {'
69 64 };
70 65
71 66 let repo_path = value_of_global_arg("repository").map(Path::new);
72 let result = (|| -> Result<(), CommandError> {
73 let config_args = values_of_global_arg("config")
74 // `get_bytes_from_path` works for OsStr the same as for Path
75 .map(hg::utils::files::get_bytes_from_path);
76 let config = hg::config::Config::load(config_args)?;
77 run(&ui, &config, repo_path, args)
78 })();
67 let config_args = values_of_global_arg("config")
68 // `get_bytes_from_path` works for OsStr the same as for Path
69 .map(hg::utils::files::get_bytes_from_path);
70 let config = hg::config::Config::load(config_args)?;
71 run(&ui, &config, repo_path, args)
72 }
79 73
80 let exit_code = match result {
81 Ok(_) => exitcode::OK,
74 fn main() {
75 let ui = ui::Ui::new();
76
77 let exit_code = match main_with_result(&ui) {
78 Ok(()) => exitcode::OK,
82 79
83 80 // Exit with a specific code and no error message to let a potential
84 81 // wrapper script fallback to Python-based Mercurial.
@@ -49,11 +49,6 b' impl Ui {'
49 49
50 50 stderr.flush().or_else(handle_stderr_error)
51 51 }
52
53 /// Write string line to stderr
54 pub fn writeln_stderr_str(&self, s: &str) -> Result<(), UiError> {
55 self.write_stderr(&format!("{}\n", s).as_bytes())
56 }
57 52 }
58 53
59 54 /// A buffered stdout writer for faster batch printing operations.
@@ -12,12 +12,6 b' Define an rhg function that will only ru'
12 12
13 13 Unimplemented command
14 14 $ rhg unimplemented-command
15 error: Found argument 'unimplemented-command' which wasn't expected, or isn't valid in this context
16
17 USAGE:
18 rhg [OPTIONS] <SUBCOMMAND>
19
20 For more information try --help
21 15 [252]
22 16
23 17 Finding root
General Comments 0
You need to be logged in to leave comments. Login now