From 92c4b32eeba44f61d754c03c6c1cecbf7a779445 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sat, 1 Oct 2022 12:04:20 +0200 Subject: [PATCH] wc: update to clap 4 --- src/uu/wc/Cargo.toml | 2 +- src/uu/wc/src/wc.rs | 33 ++++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/uu/wc/Cargo.toml b/src/uu/wc/Cargo.toml index 2b2ef1fa2..2eeeb8799 100644 --- a/src/uu/wc/Cargo.toml +++ b/src/uu/wc/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/wc.rs" [dependencies] -clap = { version = "3.2", features = ["wrap_help", "cargo"] } +clap = { version = "4.0", features = ["wrap_help", "cargo"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["pipes"] } bytecount = "0.6.3" utf-8 = "0.7.6" diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index fc97f3928..3c57fe5c6 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -21,7 +21,7 @@ use utf8::{BufReadDecoder, BufReadDecoderError}; use uucore::format_usage; use word_count::{TitledWordCount, WordCount}; -use clap::{crate_version, Arg, ArgMatches, Command}; +use clap::{crate_version, Arg, ArgAction, ArgMatches, Command}; use std::cmp::max; use std::error::Error; @@ -61,11 +61,11 @@ impl Settings { }; let settings = Self { - show_bytes: matches.contains_id(options::BYTES), - show_chars: matches.contains_id(options::CHAR), - show_lines: matches.contains_id(options::LINES), - show_words: matches.contains_id(options::WORDS), - show_max_line_length: matches.contains_id(options::MAX_LINE_LENGTH), + show_bytes: matches.get_flag(options::BYTES), + show_chars: matches.get_flag(options::CHAR), + show_lines: matches.get_flag(options::LINES), + show_words: matches.get_flag(options::WORDS), + show_max_line_length: matches.get_flag(options::MAX_LINE_LENGTH), files0_from_stdin_mode, title_quoting_style, }; @@ -205,7 +205,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { wc(&inputs, &settings) } -pub fn uu_app<'a>() -> Command<'a> { +pub fn uu_app() -> Command { Command::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) @@ -215,18 +215,19 @@ pub fn uu_app<'a>() -> Command<'a> { Arg::new(options::BYTES) .short('c') .long(options::BYTES) - .help("print the byte counts"), + .help("print the byte counts") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::CHAR) .short('m') .long(options::CHAR) - .help("print the character counts"), + .help("print the character counts") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::FILES0_FROM) .long(options::FILES0_FROM) - .takes_value(true) .value_name("F") .help( "read input from the files specified by @@ -239,24 +240,26 @@ pub fn uu_app<'a>() -> Command<'a> { Arg::new(options::LINES) .short('l') .long(options::LINES) - .help("print the newline counts"), + .help("print the newline counts") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::MAX_LINE_LENGTH) .short('L') .long(options::MAX_LINE_LENGTH) - .help("print the length of the longest line"), + .help("print the length of the longest line") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::WORDS) .short('w') .long(options::WORDS) - .help("print the word counts"), + .help("print the word counts") + .action(ArgAction::SetTrue), ) .arg( Arg::new(ARG_FILES) - .multiple_occurrences(true) - .takes_value(true) + .action(ArgAction::Append) .value_parser(ValueParser::os_string()) .value_hint(clap::ValueHint::FilePath), )