From acf4ba75fe9ea67f075b4d94940664cfa432ee16 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sat, 1 Oct 2022 11:39:47 +0200 Subject: [PATCH] tr: update to clap 4 --- src/uu/tr/Cargo.toml | 2 +- src/uu/tr/src/tr.rs | 36 ++++++++++++++++-------------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/uu/tr/Cargo.toml b/src/uu/tr/Cargo.toml index 09741e4aa..3c69b4f30 100644 --- a/src/uu/tr/Cargo.toml +++ b/src/uu/tr/Cargo.toml @@ -16,7 +16,7 @@ path = "src/tr.rs" [dependencies] nom = "7.1.1" -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" } [[bin]] diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index b7f9b413d..1001b7c83 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -11,7 +11,7 @@ mod convert; mod operation; mod unicode_table; -use clap::{crate_version, Arg, Command}; +use clap::{crate_version, Arg, ArgAction, Command}; use nom::AsBytes; use operation::{translate_input, Sequence, SqueezeOperation, TranslateOperation}; use std::io::{stdin, stdout, BufReader, BufWriter}; @@ -42,16 +42,14 @@ fn get_long_usage() -> String { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); - let after_help = get_long_usage(); - let matches = uu_app() - .after_help(&after_help[..]) + .after_help(get_long_usage()) .try_get_matches_from(args)?; - let delete_flag = matches.contains_id(options::DELETE); - let complement_flag = matches.contains_id(options::COMPLEMENT); - let squeeze_flag = matches.contains_id(options::SQUEEZE); - let truncate_set1_flag = matches.contains_id(options::TRUNCATE_SET1); + let delete_flag = matches.get_flag(options::DELETE); + let complement_flag = matches.get_flag(options::COMPLEMENT); + let squeeze_flag = matches.get_flag(options::SQUEEZE); + let truncate_set1_flag = matches.get_flag(options::TRUNCATE_SET1); let sets = matches .get_many::(options::SETS) @@ -137,7 +135,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { Ok(()) } -pub fn uu_app<'a>() -> Command<'a> { +pub fn uu_app() -> Command { Command::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) @@ -148,13 +146,15 @@ pub fn uu_app<'a>() -> Command<'a> { .visible_short_alias('C') .short('c') .long(options::COMPLEMENT) - .help("use the complement of SET1"), + .help("use the complement of SET1") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::DELETE) .short('d') .long(options::DELETE) - .help("delete characters in SET1, do not translate"), + .help("delete characters in SET1, do not translate") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::SQUEEZE) @@ -164,19 +164,15 @@ pub fn uu_app<'a>() -> Command<'a> { "replace each sequence of a repeated character that is \ listed in the last specified SET, with a single occurrence \ of that character", - ), + ) + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::TRUNCATE_SET1) .long(options::TRUNCATE_SET1) .short('t') - .help("first truncate SET1 to length of SET2"), - ) - .arg( - Arg::new(options::SETS) - .multiple_occurrences(true) - .takes_value(true) - .min_values(1) - .max_values(2), + .help("first truncate SET1 to length of SET2") + .action(ArgAction::SetTrue), ) + .arg(Arg::new(options::SETS).num_args(1..=2)) }