##// END OF EJS Templates
rhg: add a limited `rhg files` subcommand...
Antoine Cezar -
r45924:26440adb default
parent child Browse files
Show More
@@ -1,53 +1,57 b''
1 1 use clap::App;
2 2 use clap::AppSettings;
3 3 use clap::SubCommand;
4 4
5 5 mod commands;
6 6 mod error;
7 7 mod exitcode;
8 8 mod ui;
9 9 use commands::Command;
10 10
11 11 fn main() {
12 12 let mut app = App::new("rhg")
13 13 .setting(AppSettings::AllowInvalidUtf8)
14 14 .setting(AppSettings::SubcommandRequired)
15 15 .setting(AppSettings::VersionlessSubcommands)
16 16 .version("0.0.1")
17 17 .subcommand(
18 18 SubCommand::with_name("root").about(commands::root::HELP_TEXT),
19 )
20 .subcommand(
21 SubCommand::with_name("files").about(commands::files::HELP_TEXT),
19 22 );
20 23
21 24 let matches = app.clone().get_matches_safe().unwrap_or_else(|_| {
22 25 std::process::exit(exitcode::UNIMPLEMENTED_COMMAND)
23 26 });
24 27
25 28 let ui = ui::Ui::new();
26 29
27 30 let command_result = match matches.subcommand_name() {
28 31 Some(name) => match name {
29 32 "root" => commands::root::RootCommand::new(&ui).run(),
33 "files" => commands::files::FilesCommand::new(&ui).run(),
30 34 _ => std::process::exit(exitcode::UNIMPLEMENTED_COMMAND),
31 35 },
32 36 _ => {
33 37 match app.print_help() {
34 38 Ok(_) => std::process::exit(exitcode::OK),
35 39 Err(_) => std::process::exit(exitcode::ABORT),
36 40 };
37 41 }
38 42 };
39 43
40 44 match command_result {
41 45 Ok(_) => std::process::exit(exitcode::OK),
42 46 Err(e) => {
43 47 let message = e.get_error_message_bytes();
44 48 if let Some(msg) = message {
45 49 match ui.write_stderr(&msg) {
46 50 Ok(_) => (),
47 51 Err(_) => std::process::exit(exitcode::ABORT),
48 52 };
49 53 };
50 54 e.exit()
51 55 }
52 56 }
53 57 }
General Comments 0
You need to be logged in to leave comments. Login now