##// END OF EJS Templates
rhg: add a limited `rhg debugdata` subcommand...
Antoine Cezar -
r46100:f17caf8f default
parent child Browse files
Show More
@@ -1,15 +1,21 b''
1 use clap::App;
1 use clap::App;
2 use clap::AppSettings;
2 use clap::AppSettings;
3 use clap::Arg;
4 use clap::ArgGroup;
5 use clap::ArgMatches;
3 use clap::SubCommand;
6 use clap::SubCommand;
7 use hg::operations::DebugDataKind;
8 use std::convert::TryFrom;
4
9
5 mod commands;
10 mod commands;
6 mod error;
11 mod error;
7 mod exitcode;
12 mod exitcode;
8 mod ui;
13 mod ui;
9 use commands::Command;
14 use commands::Command;
15 use error::CommandError;
10
16
11 fn main() {
17 fn main() {
12 let mut app = App::new("rhg")
18 let app = App::new("rhg")
13 .setting(AppSettings::AllowInvalidUtf8)
19 .setting(AppSettings::AllowInvalidUtf8)
14 .setting(AppSettings::SubcommandRequired)
20 .setting(AppSettings::SubcommandRequired)
15 .setting(AppSettings::VersionlessSubcommands)
21 .setting(AppSettings::VersionlessSubcommands)
@@ -19,6 +25,33 b' fn main() {'
19 )
25 )
20 .subcommand(
26 .subcommand(
21 SubCommand::with_name("files").about(commands::files::HELP_TEXT),
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 let matches = app.clone().get_matches_safe().unwrap_or_else(|err| {
57 let matches = app.clone().get_matches_safe().unwrap_or_else(|err| {
@@ -28,19 +61,7 b' fn main() {'
28
61
29 let ui = ui::Ui::new();
62 let ui = ui::Ui::new();
30
63
31 let command_result = match matches.subcommand_name() {
64 let command_result = match_subcommand(matches, &ui);
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 };
44
65
45 match command_result {
66 match command_result {
46 Ok(_) => std::process::exit(exitcode::OK),
67 Ok(_) => std::process::exit(exitcode::OK),
@@ -56,3 +77,43 b' fn main() {'
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 }
@@ -68,3 +68,25 b' Listing tracked files from subdirectory'
68 Listing tracked files through broken pipe
68 Listing tracked files through broken pipe
69 $ rhg files | head -n 1
69 $ rhg files | head -n 1
70 ../../../file1
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