Mercurial > public > mercurial-scm > hg
comparison rust/rhg/src/commands/debugdata.rs @ 49640:37bc3edef76f
rhg: upgrade `clap` dependency
This one is the worst one to upgrade since v2 -> v4 broke a ton of API,
which thankfully seems saner now.
Contrary to what was done in the `hg-core/src/examples/nodemap` rewrite,
we're not switching from the "builder" pattern to the "derive" pattern,
since that would imply a much larger diff. It can be done incrementally.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Tue, 15 Nov 2022 00:02:43 +0100 |
parents | 0199712c7a6d |
children | c15b415d1bff |
comparison
equal
deleted
inserted
replaced
49639:5844cd8e81ca | 49640:37bc3edef76f |
---|---|
6 | 6 |
7 pub const HELP_TEXT: &str = " | 7 pub const HELP_TEXT: &str = " |
8 Dump the contents of a data file revision | 8 Dump the contents of a data file revision |
9 "; | 9 "; |
10 | 10 |
11 pub fn args() -> clap::App<'static, 'static> { | 11 pub fn args() -> clap::Command { |
12 clap::SubCommand::with_name("debugdata") | 12 clap::command!("debugdata") |
13 .arg( | 13 .arg( |
14 Arg::with_name("changelog") | 14 Arg::new("changelog") |
15 .help("open changelog") | 15 .help("open changelog") |
16 .short("-c") | 16 .short('c') |
17 .long("--changelog"), | 17 .action(clap::ArgAction::SetTrue), |
18 ) | 18 ) |
19 .arg( | 19 .arg( |
20 Arg::with_name("manifest") | 20 Arg::new("manifest") |
21 .help("open manifest") | 21 .help("open manifest") |
22 .short("-m") | 22 .short('m') |
23 .long("--manifest"), | 23 .action(clap::ArgAction::SetTrue), |
24 ) | 24 ) |
25 .group( | 25 .group( |
26 ArgGroup::with_name("") | 26 ArgGroup::new("revlog") |
27 .args(&["changelog", "manifest"]) | 27 .args(&["changelog", "manifest"]) |
28 .required(true), | 28 .required(true), |
29 ) | 29 ) |
30 .arg( | 30 .arg( |
31 Arg::with_name("rev") | 31 Arg::new("rev") |
32 .help("revision") | 32 .help("revision") |
33 .required(true) | 33 .required(true) |
34 .value_name("REV"), | 34 .value_name("REV"), |
35 ) | 35 ) |
36 .about(HELP_TEXT) | 36 .about(HELP_TEXT) |
38 | 38 |
39 #[timed] | 39 #[timed] |
40 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { | 40 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
41 let args = invocation.subcommand_args; | 41 let args = invocation.subcommand_args; |
42 let rev = args | 42 let rev = args |
43 .value_of("rev") | 43 .get_one::<String>("rev") |
44 .expect("rev should be a required argument"); | 44 .expect("rev should be a required argument"); |
45 let kind = | 45 let kind = match ( |
46 match (args.is_present("changelog"), args.is_present("manifest")) { | 46 args.get_one::<bool>("changelog").unwrap(), |
47 (true, false) => DebugDataKind::Changelog, | 47 args.get_one::<bool>("manifest").unwrap(), |
48 (false, true) => DebugDataKind::Manifest, | 48 ) { |
49 (true, true) => { | 49 (true, false) => DebugDataKind::Changelog, |
50 unreachable!("Should not happen since options are exclusive") | 50 (false, true) => DebugDataKind::Manifest, |
51 } | 51 (true, true) => { |
52 (false, false) => { | 52 unreachable!("Should not happen since options are exclusive") |
53 unreachable!("Should not happen since options are required") | 53 } |
54 } | 54 (false, false) => { |
55 }; | 55 unreachable!("Should not happen since options are required") |
56 } | |
57 }; | |
56 | 58 |
57 let repo = invocation.repo?; | 59 let repo = invocation.repo?; |
58 if repo.has_narrow() { | 60 if repo.has_narrow() { |
59 return Err(CommandError::unsupported( | 61 return Err(CommandError::unsupported( |
60 "support for ellipsis nodes is missing and repo has narrow enabled", | 62 "support for ellipsis nodes is missing and repo has narrow enabled", |
61 )); | 63 )); |
62 } | 64 } |
63 let data = debug_data(repo, rev, kind).map_err(|e| (e, rev))?; | 65 let data = debug_data(repo, rev, kind).map_err(|e| (e, rev.as_ref()))?; |
64 | 66 |
65 let mut stdout = invocation.ui.stdout_buffer(); | 67 let mut stdout = invocation.ui.stdout_buffer(); |
66 stdout.write_all(&data)?; | 68 stdout.write_all(&data)?; |
67 stdout.flush()?; | 69 stdout.flush()?; |
68 | 70 |