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