From 3a234b3b098b638bf19e847524ac76c9d5620e62 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sat, 1 Oct 2022 11:50:43 +0200 Subject: [PATCH] unexpand: update to clap 4 --- src/uu/unexpand/Cargo.toml | 2 +- src/uu/unexpand/src/unexpand.rs | 33 ++++++++++++++++++--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/uu/unexpand/Cargo.toml b/src/uu/unexpand/Cargo.toml index 604e4ff42..24620e934 100644 --- a/src/uu/unexpand/Cargo.toml +++ b/src/uu/unexpand/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/unexpand.rs" [dependencies] -clap = { version = "3.2", features = ["wrap_help", "cargo"] } +clap = { version = "4.0", features = ["wrap_help", "cargo"] } unicode-width = "0.1.5" uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index ef0d48c7c..27ddd994b 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -11,7 +11,7 @@ #[macro_use] extern crate uucore; -use clap::{crate_version, Arg, Command}; +use clap::{crate_version, Arg, ArgAction, Command}; use std::error::Error; use std::fmt; use std::fs::File; @@ -109,9 +109,9 @@ impl Options { Some(s) => tabstops_parse(&s.map(|s| s.as_str()).collect::>().join(","))?, }; - let aflag = (matches.contains_id(options::ALL) || matches.contains_id(options::TABS)) - && !matches.contains_id(options::FIRST_ONLY); - let uflag = !matches.contains_id(options::NO_UTF8); + let aflag = (matches.get_flag(options::ALL) || matches.contains_id(options::TABS)) + && !matches.get_flag(options::FIRST_ONLY); + let uflag = !matches.get_flag(options::NO_UTF8); let files = match matches.get_one::(options::FILE) { Some(v) => vec![v.to_string()], @@ -172,7 +172,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { unexpand(&Options::new(&matches)?).map_err_context(String::new) } -pub fn uu_app<'a>() -> Command<'a> { +pub fn uu_app() -> Command { Command::new(uucore::util_name()) .name(NAME) .version(crate_version!()) @@ -182,37 +182,40 @@ pub fn uu_app<'a>() -> Command<'a> { .arg( Arg::new(options::FILE) .hide(true) - .multiple_occurrences(true) - .value_hint(clap::ValueHint::FilePath) + .action(ArgAction::Append) + .value_hint(clap::ValueHint::FilePath), ) .arg( Arg::new(options::ALL) .short('a') .long(options::ALL) .help("convert all blanks, instead of just initial blanks") - .takes_value(false), + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::FIRST_ONLY) .long(options::FIRST_ONLY) .help("convert only leading sequences of blanks (overrides -a)") - .takes_value(false), + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::TABS) .short('t') .long(options::TABS) - .help("use comma separated LIST of tab positions or have tabs N characters apart instead of 8 (enables -a)") - .takes_value(true) - .multiple_occurrences(true) - .value_name("N, LIST") + .help( + "use comma separated LIST of tab positions or have tabs N characters \ + apart instead of 8 (enables -a)", + ) + .action(ArgAction::Append) + .value_name("N, LIST"), ) .arg( Arg::new(options::NO_UTF8) .short('U') .long(options::NO_UTF8) - .takes_value(false) - .help("interpret input file as 8-bit ASCII rather than UTF-8")) + .help("interpret input file as 8-bit ASCII rather than UTF-8") + .action(ArgAction::SetTrue), + ) } fn open(path: &str) -> BufReader> {