From 7cebb2563b34b4fdf5991006467bebbe338ca4b5 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Tue, 11 Jan 2022 14:17:22 +0100 Subject: [PATCH] numfmt: clap 3 --- src/uu/numfmt/Cargo.toml | 2 +- src/uu/numfmt/src/numfmt.rs | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/uu/numfmt/Cargo.toml b/src/uu/numfmt/Cargo.toml index 29313350f..fccfb7c7e 100644 --- a/src/uu/numfmt/Cargo.toml +++ b/src/uu/numfmt/Cargo.toml @@ -15,7 +15,7 @@ edition = "2018" path = "src/numfmt.rs" [dependencies] -clap = { version = "2.33", features = ["wrap_help"] } +clap = { version = "3.0", features = ["wrap_help", "cargo"] } uucore = { version=">=0.0.10", package="uucore", path="../../uucore" } uucore_procs = { version=">=0.0.7", package="uucore_procs", path="../../uucore_procs" } diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index b84b9ab1b..29f1914d5 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -159,7 +159,7 @@ fn parse_options(args: &ArgMatches) -> Result { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let usage = usage(); - let matches = uu_app().usage(&usage[..]).get_matches_from(args); + let matches = uu_app().override_usage(&usage[..]).get_matches_from(args); let result = parse_options(&matches).and_then(|options| match matches.values_of(options::NUMBER) { @@ -178,42 +178,42 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } } -pub fn uu_app() -> App<'static, 'static> { +pub fn uu_app<'a>() -> App<'a> { App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .after_help(LONG_HELP) .setting(AppSettings::AllowNegativeNumbers) .arg( - Arg::with_name(options::DELIMITER) - .short("d") + Arg::new(options::DELIMITER) + .short('d') .long(options::DELIMITER) .value_name("X") .help("use X instead of whitespace for field delimiter"), ) .arg( - Arg::with_name(options::FIELD) + Arg::new(options::FIELD) .long(options::FIELD) .help("replace the numbers in these input fields (default=1) see FIELDS below") .value_name("FIELDS") .default_value(options::FIELD_DEFAULT), ) .arg( - Arg::with_name(options::FROM) + Arg::new(options::FROM) .long(options::FROM) .help("auto-scale input numbers to UNITs; see UNIT below") .value_name("UNIT") .default_value(options::FROM_DEFAULT), ) .arg( - Arg::with_name(options::TO) + Arg::new(options::TO) .long(options::TO) .help("auto-scale output numbers to UNITs; see UNIT below") .value_name("UNIT") .default_value(options::TO_DEFAULT), ) .arg( - Arg::with_name(options::PADDING) + Arg::new(options::PADDING) .long(options::PADDING) .help( "pad the output to N characters; positive N will \ @@ -224,18 +224,18 @@ pub fn uu_app() -> App<'static, 'static> { .value_name("N"), ) .arg( - Arg::with_name(options::HEADER) + Arg::new(options::HEADER) .long(options::HEADER) .help( "print (without converting) the first N header lines; \ N defaults to 1 if not specified", ) .value_name("N") - .default_value(options::HEADER_DEFAULT) + .default_missing_value(options::HEADER_DEFAULT) .hide_default_value(true), ) .arg( - Arg::with_name(options::ROUND) + Arg::new(options::ROUND) .long(options::ROUND) .help( "use METHOD for rounding when scaling; METHOD can be: up,\ @@ -246,7 +246,7 @@ pub fn uu_app() -> App<'static, 'static> { .possible_values(&["up", "down", "from-zero", "towards-zero", "nearest"]), ) .arg( - Arg::with_name(options::SUFFIX) + Arg::new(options::SUFFIX) .long(options::SUFFIX) .help( "print SUFFIX after each formatted number, and accept \ @@ -254,5 +254,9 @@ pub fn uu_app() -> App<'static, 'static> { ) .value_name("SUFFIX"), ) - .arg(Arg::with_name(options::NUMBER).hidden(true).multiple(true)) + .arg( + Arg::new(options::NUMBER) + .hide(true) + .multiple_occurrences(true), + ) }