From 4cfc90c0774734718294bc563c7d20115203f1b0 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 30 Sep 2022 16:31:12 +0200 Subject: [PATCH] seq: update to clap 4 --- src/uu/seq/Cargo.toml | 2 +- src/uu/seq/src/seq.rs | 27 ++++++++++----------------- tests/by-util/test_seq.rs | 4 ++-- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/uu/seq/Cargo.toml b/src/uu/seq/Cargo.toml index 632785311..cd9b1a7ce 100644 --- a/src/uu/seq/Cargo.toml +++ b/src/uu/seq/Cargo.toml @@ -17,7 +17,7 @@ path = "src/seq.rs" [dependencies] bigdecimal = "0.3" -clap = { version = "3.2", features = ["wrap_help", "cargo"] } +clap = { version = "4.0", features = ["wrap_help", "cargo"] } num-bigint = "0.4.0" num-traits = "0.2.15" uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["memo"] } diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 6038af270..280b9355b 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -7,7 +7,7 @@ use std::io::{stdout, ErrorKind, Write}; use std::process::exit; -use clap::{crate_version, Arg, Command}; +use clap::{crate_version, Arg, ArgAction, Command}; use num_traits::Zero; use uucore::error::FromIo; @@ -77,7 +77,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .map(|s| s.as_str()) .unwrap_or("\n") .to_string(), - widths: matches.contains_id(OPT_WIDTHS), + widths: matches.get_flag(OPT_WIDTHS), format: matches.get_one::(OPT_FORMAT).map(|s| s.as_str()), }; @@ -152,7 +152,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } } -pub fn uu_app<'a>() -> Command<'a> { +pub fn uu_app() -> Command { Command::new(uucore::util_name()) .trailing_var_arg(true) .allow_negative_numbers(true) @@ -164,38 +164,31 @@ pub fn uu_app<'a>() -> Command<'a> { Arg::new(OPT_SEPARATOR) .short('s') .long("separator") - .help("Separator character (defaults to \\n)") - .takes_value(true) - .number_of_values(1), + .help("Separator character (defaults to \\n)"), ) .arg( Arg::new(OPT_TERMINATOR) .short('t') .long("terminator") - .help("Terminator character (defaults to \\n)") - .takes_value(true) - .number_of_values(1), + .help("Terminator character (defaults to \\n)"), ) .arg( Arg::new(OPT_WIDTHS) .short('w') .long("widths") - .help("Equalize widths of all numbers by padding with zeros"), + .help("Equalize widths of all numbers by padding with zeros") + .action(ArgAction::SetTrue), ) .arg( Arg::new(OPT_FORMAT) .short('f') .long(OPT_FORMAT) - .help("use printf style floating-point FORMAT") - .takes_value(true) - .number_of_values(1), + .help("use printf style floating-point FORMAT"), ) .arg( Arg::new(ARG_NUMBERS) - .multiple_occurrences(true) - .takes_value(true) - .max_values(3) - .required(true), + .action(ArgAction::Append) + .num_args(1..=3), ) } diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index c3ca61081..a6fa36353 100644 --- a/tests/by-util/test_seq.rs +++ b/tests/by-util/test_seq.rs @@ -26,13 +26,13 @@ fn test_hex_rejects_sign_after_identifier() { .fails() .no_stdout() .stderr_contains("which wasn't expected, or isn't valid in this context") - .stderr_contains("For more information try --help"); + .stderr_contains("For more information try '--help'"); new_ucmd!() .args(&["-0x+123ABC"]) .fails() .no_stdout() .stderr_contains("which wasn't expected, or isn't valid in this context") - .stderr_contains("For more information try --help"); + .stderr_contains("For more information try '--help'"); } #[test]