Mercurial > hg
comparison rust/rhg/src/main.rs @ 45542:33ded2d3f4fc
rhg: add a limited `rhg cat -r` subcommand
It only supports revision specification (rev or full hash) and the list of files
to cat.
Differential Revision: https://phab.mercurial-scm.org/D9052
author | Antoine Cezar <antoine.cezar@octobus.net> |
---|---|
date | Tue, 15 Sep 2020 16:51:11 +0200 |
parents | 2f8227a12592 |
children | ead435aa5294 |
comparison
equal
deleted
inserted
replaced
45541:522ec3dc44b9 | 45542:33ded2d3f4fc |
---|---|
34 .long("--revision") | 34 .long("--revision") |
35 .value_name("REV") | 35 .value_name("REV") |
36 .takes_value(true), | 36 .takes_value(true), |
37 ) | 37 ) |
38 .about(commands::files::HELP_TEXT), | 38 .about(commands::files::HELP_TEXT), |
39 ) | |
40 .subcommand( | |
41 SubCommand::with_name("cat") | |
42 .arg( | |
43 Arg::with_name("rev") | |
44 .help("search the repository as it is in REV") | |
45 .short("-r") | |
46 .long("--revision") | |
47 .value_name("REV") | |
48 .takes_value(true), | |
49 ) | |
50 .arg( | |
51 clap::Arg::with_name("files") | |
52 .required(true) | |
53 .multiple(true) | |
54 .empty_values(false) | |
55 .value_name("FILE") | |
56 .help("Activity to start: activity@category"), | |
57 ) | |
58 .about(commands::cat::HELP_TEXT), | |
39 ) | 59 ) |
40 .subcommand( | 60 .subcommand( |
41 SubCommand::with_name("debugdata") | 61 SubCommand::with_name("debugdata") |
42 .about(commands::debugdata::HELP_TEXT) | 62 .about(commands::debugdata::HELP_TEXT) |
43 .arg( | 63 .arg( |
96 match matches.subcommand() { | 116 match matches.subcommand() { |
97 ("root", _) => commands::root::RootCommand::new().run(&ui), | 117 ("root", _) => commands::root::RootCommand::new().run(&ui), |
98 ("files", Some(matches)) => { | 118 ("files", Some(matches)) => { |
99 commands::files::FilesCommand::try_from(matches)?.run(&ui) | 119 commands::files::FilesCommand::try_from(matches)?.run(&ui) |
100 } | 120 } |
121 ("cat", Some(matches)) => { | |
122 commands::cat::CatCommand::try_from(matches)?.run(&ui) | |
123 } | |
101 ("debugdata", Some(matches)) => { | 124 ("debugdata", Some(matches)) => { |
102 commands::debugdata::DebugDataCommand::try_from(matches)?.run(&ui) | 125 commands::debugdata::DebugDataCommand::try_from(matches)?.run(&ui) |
103 } | 126 } |
104 _ => unreachable!(), // Because of AppSettings::SubcommandRequired, | 127 _ => unreachable!(), // Because of AppSettings::SubcommandRequired, |
105 } | 128 } |
109 type Error = CommandError; | 132 type Error = CommandError; |
110 | 133 |
111 fn try_from(args: &'a ArgMatches) -> Result<Self, Self::Error> { | 134 fn try_from(args: &'a ArgMatches) -> Result<Self, Self::Error> { |
112 let rev = args.value_of("rev"); | 135 let rev = args.value_of("rev"); |
113 Ok(commands::files::FilesCommand::new(rev)) | 136 Ok(commands::files::FilesCommand::new(rev)) |
137 } | |
138 } | |
139 | |
140 impl<'a> TryFrom<&'a ArgMatches<'_>> for commands::cat::CatCommand<'a> { | |
141 type Error = CommandError; | |
142 | |
143 fn try_from(args: &'a ArgMatches) -> Result<Self, Self::Error> { | |
144 let rev = args.value_of("rev"); | |
145 let files = match args.values_of("files") { | |
146 Some(files) => files.collect(), | |
147 None => vec![], | |
148 }; | |
149 Ok(commands::cat::CatCommand::new(rev, files)) | |
114 } | 150 } |
115 } | 151 } |
116 | 152 |
117 impl<'a> TryFrom<&'a ArgMatches<'_>> | 153 impl<'a> TryFrom<&'a ArgMatches<'_>> |
118 for commands::debugdata::DebugDataCommand<'a> | 154 for commands::debugdata::DebugDataCommand<'a> |