1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

tr: update to clap 4

This commit is contained in:
Terts Diepraam 2022-10-01 11:39:47 +02:00
parent e54e2e0252
commit acf4ba75fe
2 changed files with 17 additions and 21 deletions

View file

@ -16,7 +16,7 @@ path = "src/tr.rs"
[dependencies] [dependencies]
nom = "7.1.1" 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" } uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
[[bin]] [[bin]]

View file

@ -11,7 +11,7 @@ mod convert;
mod operation; mod operation;
mod unicode_table; mod unicode_table;
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, ArgAction, Command};
use nom::AsBytes; use nom::AsBytes;
use operation::{translate_input, Sequence, SqueezeOperation, TranslateOperation}; use operation::{translate_input, Sequence, SqueezeOperation, TranslateOperation};
use std::io::{stdin, stdout, BufReader, BufWriter}; use std::io::{stdin, stdout, BufReader, BufWriter};
@ -42,16 +42,14 @@ fn get_long_usage() -> String {
pub fn uumain(args: impl uucore::Args) -> UResult<()> { pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = args.collect_lossy(); let args = args.collect_lossy();
let after_help = get_long_usage();
let matches = uu_app() let matches = uu_app()
.after_help(&after_help[..]) .after_help(get_long_usage())
.try_get_matches_from(args)?; .try_get_matches_from(args)?;
let delete_flag = matches.contains_id(options::DELETE); let delete_flag = matches.get_flag(options::DELETE);
let complement_flag = matches.contains_id(options::COMPLEMENT); let complement_flag = matches.get_flag(options::COMPLEMENT);
let squeeze_flag = matches.contains_id(options::SQUEEZE); let squeeze_flag = matches.get_flag(options::SQUEEZE);
let truncate_set1_flag = matches.contains_id(options::TRUNCATE_SET1); let truncate_set1_flag = matches.get_flag(options::TRUNCATE_SET1);
let sets = matches let sets = matches
.get_many::<String>(options::SETS) .get_many::<String>(options::SETS)
@ -137,7 +135,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Ok(()) Ok(())
} }
pub fn uu_app<'a>() -> Command<'a> { pub fn uu_app() -> Command {
Command::new(uucore::util_name()) Command::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
@ -148,13 +146,15 @@ pub fn uu_app<'a>() -> Command<'a> {
.visible_short_alias('C') .visible_short_alias('C')
.short('c') .short('c')
.long(options::COMPLEMENT) .long(options::COMPLEMENT)
.help("use the complement of SET1"), .help("use the complement of SET1")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::DELETE) Arg::new(options::DELETE)
.short('d') .short('d')
.long(options::DELETE) .long(options::DELETE)
.help("delete characters in SET1, do not translate"), .help("delete characters in SET1, do not translate")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::SQUEEZE) Arg::new(options::SQUEEZE)
@ -164,19 +164,15 @@ pub fn uu_app<'a>() -> Command<'a> {
"replace each sequence of a repeated character that is \ "replace each sequence of a repeated character that is \
listed in the last specified SET, with a single occurrence \ listed in the last specified SET, with a single occurrence \
of that character", of that character",
), )
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::TRUNCATE_SET1) Arg::new(options::TRUNCATE_SET1)
.long(options::TRUNCATE_SET1) .long(options::TRUNCATE_SET1)
.short('t') .short('t')
.help("first truncate SET1 to length of SET2"), .help("first truncate SET1 to length of SET2")
) .action(ArgAction::SetTrue),
.arg(
Arg::new(options::SETS)
.multiple_occurrences(true)
.takes_value(true)
.min_values(1)
.max_values(2),
) )
.arg(Arg::new(options::SETS).num_args(1..=2))
} }