Mercurial > public > mercurial-scm > hg
diff 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 |
line wrap: on
line diff
--- a/rust/rhg/src/commands/debugdata.rs Mon Nov 14 17:18:56 2022 +0100 +++ b/rust/rhg/src/commands/debugdata.rs Tue Nov 15 00:02:43 2022 +0100 @@ -8,27 +8,27 @@ Dump the contents of a data file revision "; -pub fn args() -> clap::App<'static, 'static> { - clap::SubCommand::with_name("debugdata") +pub fn args() -> clap::Command { + clap::command!("debugdata") .arg( - Arg::with_name("changelog") + Arg::new("changelog") .help("open changelog") - .short("-c") - .long("--changelog"), + .short('c') + .action(clap::ArgAction::SetTrue), ) .arg( - Arg::with_name("manifest") + Arg::new("manifest") .help("open manifest") - .short("-m") - .long("--manifest"), + .short('m') + .action(clap::ArgAction::SetTrue), ) .group( - ArgGroup::with_name("") + ArgGroup::new("revlog") .args(&["changelog", "manifest"]) .required(true), ) .arg( - Arg::with_name("rev") + Arg::new("rev") .help("revision") .required(true) .value_name("REV"), @@ -40,19 +40,21 @@ pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { let args = invocation.subcommand_args; let rev = args - .value_of("rev") + .get_one::<String>("rev") .expect("rev should be a required argument"); - let kind = - match (args.is_present("changelog"), args.is_present("manifest")) { - (true, false) => DebugDataKind::Changelog, - (false, true) => DebugDataKind::Manifest, - (true, true) => { - unreachable!("Should not happen since options are exclusive") - } - (false, false) => { - unreachable!("Should not happen since options are required") - } - }; + let kind = match ( + args.get_one::<bool>("changelog").unwrap(), + args.get_one::<bool>("manifest").unwrap(), + ) { + (true, false) => DebugDataKind::Changelog, + (false, true) => DebugDataKind::Manifest, + (true, true) => { + unreachable!("Should not happen since options are exclusive") + } + (false, false) => { + unreachable!("Should not happen since options are required") + } + }; let repo = invocation.repo?; if repo.has_narrow() { @@ -60,7 +62,7 @@ "support for ellipsis nodes is missing and repo has narrow enabled", )); } - let data = debug_data(repo, rev, kind).map_err(|e| (e, rev))?; + let data = debug_data(repo, rev, kind).map_err(|e| (e, rev.as_ref()))?; let mut stdout = invocation.ui.stdout_buffer(); stdout.write_all(&data)?;