Show More
@@ -1,58 +1,119 b'' | |||
|
1 | 1 | use clap::App; |
|
2 | 2 | use clap::AppSettings; |
|
3 | use clap::Arg; | |
|
4 | use clap::ArgGroup; | |
|
5 | use clap::ArgMatches; | |
|
3 | 6 | use clap::SubCommand; |
|
7 | use hg::operations::DebugDataKind; | |
|
8 | use std::convert::TryFrom; | |
|
4 | 9 | |
|
5 | 10 | mod commands; |
|
6 | 11 | mod error; |
|
7 | 12 | mod exitcode; |
|
8 | 13 | mod ui; |
|
9 | 14 | use commands::Command; |
|
15 | use error::CommandError; | |
|
10 | 16 | |
|
11 | 17 | fn main() { |
|
12 |
let |
|
|
18 | let app = App::new("rhg") | |
|
13 | 19 | .setting(AppSettings::AllowInvalidUtf8) |
|
14 | 20 | .setting(AppSettings::SubcommandRequired) |
|
15 | 21 | .setting(AppSettings::VersionlessSubcommands) |
|
16 | 22 | .version("0.0.1") |
|
17 | 23 | .subcommand( |
|
18 | 24 | SubCommand::with_name("root").about(commands::root::HELP_TEXT), |
|
19 | 25 | ) |
|
20 | 26 | .subcommand( |
|
21 | 27 | SubCommand::with_name("files").about(commands::files::HELP_TEXT), |
|
28 | ) | |
|
29 | .subcommand( | |
|
30 | SubCommand::with_name("debugdata") | |
|
31 | .about(commands::debugdata::HELP_TEXT) | |
|
32 | .arg( | |
|
33 | Arg::with_name("changelog") | |
|
34 | .help("open changelog") | |
|
35 | .short("-c") | |
|
36 | .long("--changelog"), | |
|
37 | ) | |
|
38 | .arg( | |
|
39 | Arg::with_name("manifest") | |
|
40 | .help("open manifest") | |
|
41 | .short("-m") | |
|
42 | .long("--manifest"), | |
|
43 | ) | |
|
44 | .group( | |
|
45 | ArgGroup::with_name("") | |
|
46 | .args(&["changelog", "manifest"]) | |
|
47 | .required(true), | |
|
48 | ) | |
|
49 | .arg( | |
|
50 | Arg::with_name("rev") | |
|
51 | .help("revision") | |
|
52 | .required(true) | |
|
53 | .value_name("REV"), | |
|
54 | ), | |
|
22 | 55 | ); |
|
23 | 56 | |
|
24 | 57 | let matches = app.clone().get_matches_safe().unwrap_or_else(|err| { |
|
25 | 58 | let _ = ui::Ui::new().writeln_stderr_str(&err.message); |
|
26 | 59 | std::process::exit(exitcode::UNIMPLEMENTED_COMMAND) |
|
27 | 60 | }); |
|
28 | 61 | |
|
29 | 62 | let ui = ui::Ui::new(); |
|
30 | 63 | |
|
31 |
let command_result = match |
|
|
32 | Some(name) => match name { | |
|
33 | "root" => commands::root::RootCommand::new().run(&ui), | |
|
34 | "files" => commands::files::FilesCommand::new().run(&ui), | |
|
35 | _ => std::process::exit(exitcode::UNIMPLEMENTED_COMMAND), | |
|
36 | }, | |
|
37 | _ => { | |
|
38 | match app.print_help() { | |
|
39 | Ok(_) => std::process::exit(exitcode::OK), | |
|
40 | Err(_) => std::process::exit(exitcode::ABORT), | |
|
41 | }; | |
|
42 | } | |
|
43 | }; | |
|
64 | let command_result = match_subcommand(matches, &ui); | |
|
44 | 65 | |
|
45 | 66 | match command_result { |
|
46 | 67 | Ok(_) => std::process::exit(exitcode::OK), |
|
47 | 68 | Err(e) => { |
|
48 | 69 | let message = e.get_error_message_bytes(); |
|
49 | 70 | if let Some(msg) = message { |
|
50 | 71 | match ui.write_stderr(&msg) { |
|
51 | 72 | Ok(_) => (), |
|
52 | 73 | Err(_) => std::process::exit(exitcode::ABORT), |
|
53 | 74 | }; |
|
54 | 75 | }; |
|
55 | 76 | e.exit() |
|
56 | 77 | } |
|
57 | 78 | } |
|
58 | 79 | } |
|
80 | ||
|
81 | fn match_subcommand( | |
|
82 | matches: ArgMatches, | |
|
83 | ui: &ui::Ui, | |
|
84 | ) -> Result<(), CommandError> { | |
|
85 | match matches.subcommand() { | |
|
86 | ("root", _) => commands::root::RootCommand::new().run(&ui), | |
|
87 | ("files", _) => commands::files::FilesCommand::new().run(&ui), | |
|
88 | ("debugdata", Some(matches)) => { | |
|
89 | commands::debugdata::DebugDataCommand::try_from(matches)?.run(&ui) | |
|
90 | } | |
|
91 | _ => unreachable!(), // Because of AppSettings::SubcommandRequired, | |
|
92 | } | |
|
93 | } | |
|
94 | ||
|
95 | impl<'a> TryFrom<&'a ArgMatches<'_>> | |
|
96 | for commands::debugdata::DebugDataCommand<'a> | |
|
97 | { | |
|
98 | type Error = CommandError; | |
|
99 | ||
|
100 | fn try_from(args: &'a ArgMatches) -> Result<Self, Self::Error> { | |
|
101 | let rev = args | |
|
102 | .value_of("rev") | |
|
103 | .expect("rev should be a required argument"); | |
|
104 | let kind = match ( | |
|
105 | args.is_present("changelog"), | |
|
106 | args.is_present("manifest"), | |
|
107 | ) { | |
|
108 | (true, false) => DebugDataKind::Changelog, | |
|
109 | (false, true) => DebugDataKind::Manifest, | |
|
110 | (true, true) => { | |
|
111 | unreachable!("Should not happen since options are exclusive") | |
|
112 | } | |
|
113 | (false, false) => { | |
|
114 | unreachable!("Should not happen since options are required") | |
|
115 | } | |
|
116 | }; | |
|
117 | Ok(commands::debugdata::DebugDataCommand::new(rev, kind)) | |
|
118 | } | |
|
119 | } |
@@ -1,70 +1,92 b'' | |||
|
1 | 1 | #require rust |
|
2 | 2 | |
|
3 | 3 | Define an rhg function that will only run if rhg exists |
|
4 | 4 | $ rhg() { |
|
5 | 5 | > if [ -f "$RUNTESTDIR/../rust/target/debug/rhg" ]; then |
|
6 | 6 | > "$RUNTESTDIR/../rust/target/debug/rhg" "$@" |
|
7 | 7 | > else |
|
8 | 8 | > echo "skipped: Cannot find rhg. Try to run cargo build in rust/rhg." |
|
9 | 9 | > exit 80 |
|
10 | 10 | > fi |
|
11 | 11 | > } |
|
12 | 12 | |
|
13 | 13 | Unimplemented command |
|
14 | 14 | $ rhg unimplemented-command |
|
15 | 15 | error: Found argument 'unimplemented-command' which wasn't expected, or isn't valid in this context |
|
16 | 16 | |
|
17 | 17 | USAGE: |
|
18 | 18 | rhg <SUBCOMMAND> |
|
19 | 19 | |
|
20 | 20 | For more information try --help |
|
21 | 21 | [252] |
|
22 | 22 | |
|
23 | 23 | Finding root |
|
24 | 24 | $ rhg root |
|
25 | 25 | abort: no repository found in '$TESTTMP' (.hg not found)! |
|
26 | 26 | [255] |
|
27 | 27 | |
|
28 | 28 | $ hg init repository |
|
29 | 29 | $ cd repository |
|
30 | 30 | $ rhg root |
|
31 | 31 | $TESTTMP/repository |
|
32 | 32 | |
|
33 | 33 | Unwritable file descriptor |
|
34 | 34 | $ rhg root > /dev/full |
|
35 | 35 | abort: No space left on device (os error 28) |
|
36 | 36 | [255] |
|
37 | 37 | |
|
38 | 38 | Deleted repository |
|
39 | 39 | $ rm -rf `pwd` |
|
40 | 40 | $ rhg root |
|
41 | 41 | abort: error getting current working directory: $ENOENT$ |
|
42 | 42 | [255] |
|
43 | 43 | |
|
44 | 44 | Listing tracked files |
|
45 | 45 | $ cd $TESTTMP |
|
46 | 46 | $ hg init repository |
|
47 | 47 | $ cd repository |
|
48 | 48 | $ for i in 1 2 3; do |
|
49 | 49 | > echo $i >> file$i |
|
50 | 50 | > hg add file$i |
|
51 | 51 | > done |
|
52 | 52 | > hg commit -m "commit $i" -q |
|
53 | 53 | |
|
54 | 54 | Listing tracked files from root |
|
55 | 55 | $ rhg files |
|
56 | 56 | file1 |
|
57 | 57 | file2 |
|
58 | 58 | file3 |
|
59 | 59 | |
|
60 | 60 | Listing tracked files from subdirectory |
|
61 | 61 | $ mkdir -p path/to/directory |
|
62 | 62 | $ cd path/to/directory |
|
63 | 63 | $ rhg files |
|
64 | 64 | ../../../file1 |
|
65 | 65 | ../../../file2 |
|
66 | 66 | ../../../file3 |
|
67 | 67 | |
|
68 | 68 | Listing tracked files through broken pipe |
|
69 | 69 | $ rhg files | head -n 1 |
|
70 | 70 | ../../../file1 |
|
71 | ||
|
72 | Debuging data in inline index | |
|
73 | $ cd $TESTTMP | |
|
74 | $ rm -rf repository | |
|
75 | $ hg init repository | |
|
76 | $ cd repository | |
|
77 | $ for i in 1 2 3; do | |
|
78 | > echo $i >> file$i | |
|
79 | > hg add file$i | |
|
80 | > hg commit -m "commit $i" -q | |
|
81 | > done | |
|
82 | $ rhg debugdata -c 2 | |
|
83 | e36fa63d37a576b27a69057598351db6ee5746bd | |
|
84 | test | |
|
85 | 0 0 | |
|
86 | file3 | |
|
87 | ||
|
88 | commit 3 (no-eol) | |
|
89 | $ rhg debugdata -m 2 | |
|
90 | file1\x00b8e02f6433738021a065f94175c7cd23db5f05be (esc) | |
|
91 | file2\x005d9299349fc01ddd25d0070d149b124d8f10411e (esc) | |
|
92 | file3\x002661d26c649684b482d10f91960cc3db683c38b4 (esc) |
General Comments 0
You need to be logged in to leave comments.
Login now