From 62b963a353d10d2dd1232fc7e2ed4096957769e3 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Fri, 30 Sep 2022 16:14:31 +0200 Subject: [PATCH] ptx: update to clap 4 --- src/uu/ptx/Cargo.toml | 2 +- src/uu/ptx/src/ptx.rs | 58 +++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/uu/ptx/Cargo.toml b/src/uu/ptx/Cargo.toml index bdf3d42a3..6863a690d 100644 --- a/src/uu/ptx/Cargo.toml +++ b/src/uu/ptx/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/ptx.rs" [dependencies] -clap = { version = "3.2", features = ["wrap_help", "cargo"] } +clap = { version = "4.0", features = ["wrap_help", "cargo"] } regex = "1.6.0" uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 380c711f0..9f0570a28 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -7,7 +7,7 @@ // spell-checker:ignore (ToDOs) corasick memchr Roff trunc oset iset CHARCLASS -use clap::{crate_version, Arg, Command}; +use clap::{crate_version, Arg, ArgAction, Command}; use regex::Regex; use std::cmp; use std::collections::{BTreeSet, HashMap, HashSet}; @@ -230,7 +230,7 @@ impl Display for PtxError { fn get_config(matches: &clap::ArgMatches) -> UResult { let mut config: Config = Default::default(); let err_msg = "parsing options failed"; - if matches.contains_id(options::TRADITIONAL) { + if matches.get_flag(options::TRADITIONAL) { config.gnu_ext = false; config.format = OutFormat::Roff; config.context_regex = "[^ \t\n]+".to_owned(); @@ -240,10 +240,10 @@ fn get_config(matches: &clap::ArgMatches) -> UResult { if matches.contains_id(options::SENTENCE_REGEXP) { return Err(PtxError::NotImplemented("-S").into()); } - config.auto_ref = matches.contains_id(options::AUTO_REFERENCE); - config.input_ref = matches.contains_id(options::REFERENCES); - config.right_ref &= matches.contains_id(options::RIGHT_SIDE_REFS); - config.ignore_case = matches.contains_id(options::IGNORE_CASE); + config.auto_ref = matches.get_flag(options::AUTO_REFERENCE); + config.input_ref = matches.get_flag(options::REFERENCES); + config.right_ref &= matches.get_flag(options::RIGHT_SIDE_REFS); + config.ignore_case = matches.get_flag(options::IGNORE_CASE); if matches.contains_id(options::MACRO_NAME) { config.macro_name = matches .get_one::(options::MACRO_NAME) @@ -270,10 +270,10 @@ fn get_config(matches: &clap::ArgMatches) -> UResult { .parse() .map_err(PtxError::ParseError)?; } - if matches.contains_id(options::FORMAT_ROFF) { + if matches.get_flag(options::FORMAT_ROFF) { config.format = OutFormat::Roff; } - if matches.contains_id(options::FORMAT_TEX) { + if matches.get_flag(options::FORMAT_TEX) { config.format = OutFormat::Tex; } Ok(config) @@ -745,7 +745,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { write_traditional_output(&config, &file_map, &word_set, &output_file) } -pub fn uu_app<'a>() -> Command<'a> { +pub fn uu_app() -> Command { Command::new(uucore::util_name()) .name(NAME) .about(ABOUT) @@ -755,7 +755,7 @@ pub fn uu_app<'a>() -> Command<'a> { .arg( Arg::new(options::FILE) .hide(true) - .multiple_occurrences(true) + .action(ArgAction::Append) .value_hint(clap::ValueHint::FilePath), ) .arg( @@ -763,64 +763,63 @@ pub fn uu_app<'a>() -> Command<'a> { .short('A') .long(options::AUTO_REFERENCE) .help("output automatically generated references") - .takes_value(false), + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::TRADITIONAL) .short('G') .long(options::TRADITIONAL) - .help("behave more like System V 'ptx'"), + .help("behave more like System V 'ptx'") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::FLAG_TRUNCATION) .short('F') .long(options::FLAG_TRUNCATION) .help("use STRING for flagging line truncations") - .value_name("STRING") - .takes_value(true), + .value_name("STRING"), ) .arg( Arg::new(options::MACRO_NAME) .short('M') .long(options::MACRO_NAME) .help("macro name to use instead of 'xx'") - .value_name("STRING") - .takes_value(true), + .value_name("STRING"), ) .arg( Arg::new(options::FORMAT_ROFF) .short('O') .long(options::FORMAT_ROFF) - .help("generate output as roff directives"), + .help("generate output as roff directives") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::RIGHT_SIDE_REFS) .short('R') .long(options::RIGHT_SIDE_REFS) .help("put references at right, not counted in -w") - .takes_value(false), + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::SENTENCE_REGEXP) .short('S') .long(options::SENTENCE_REGEXP) .help("for end of lines or end of sentences") - .value_name("REGEXP") - .takes_value(true), + .value_name("REGEXP"), ) .arg( Arg::new(options::FORMAT_TEX) .short('T') .long(options::FORMAT_TEX) - .help("generate output as TeX directives"), + .help("generate output as TeX directives") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::WORD_REGEXP) .short('W') .long(options::WORD_REGEXP) .help("use REGEXP to match each keyword") - .value_name("REGEXP") - .takes_value(true), + .value_name("REGEXP"), ) .arg( Arg::new(options::BREAK_FILE) @@ -828,7 +827,6 @@ pub fn uu_app<'a>() -> Command<'a> { .long(options::BREAK_FILE) .help("word break characters in this FILE") .value_name("FILE") - .takes_value(true) .value_hint(clap::ValueHint::FilePath), ) .arg( @@ -836,15 +834,14 @@ pub fn uu_app<'a>() -> Command<'a> { .short('f') .long(options::IGNORE_CASE) .help("fold lower case to upper case for sorting") - .takes_value(false), + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::GAP_SIZE) .short('g') .long(options::GAP_SIZE) .help("gap size in columns between output fields") - .value_name("NUMBER") - .takes_value(true), + .value_name("NUMBER"), ) .arg( Arg::new(options::IGNORE_FILE) @@ -852,7 +849,6 @@ pub fn uu_app<'a>() -> Command<'a> { .long(options::IGNORE_FILE) .help("read ignore word list from FILE") .value_name("FILE") - .takes_value(true) .value_hint(clap::ValueHint::FilePath), ) .arg( @@ -861,7 +857,6 @@ pub fn uu_app<'a>() -> Command<'a> { .long(options::ONLY_FILE) .help("read only word list from this FILE") .value_name("FILE") - .takes_value(true) .value_hint(clap::ValueHint::FilePath), ) .arg( @@ -870,14 +865,13 @@ pub fn uu_app<'a>() -> Command<'a> { .long(options::REFERENCES) .help("first field of each line is a reference") .value_name("FILE") - .takes_value(false), + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::WIDTH) .short('w') .long(options::WIDTH) .help("output width in columns, reference excluded") - .value_name("NUMBER") - .takes_value(true), + .value_name("NUMBER"), ) }