From b007318b5154cb72574b19de2423fa890749d8ee Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Thu, 29 Sep 2022 17:11:01 +0200 Subject: [PATCH] echo: update to clap 4 --- src/uu/echo/Cargo.toml | 2 +- src/uu/echo/src/echo.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/uu/echo/Cargo.toml b/src/uu/echo/Cargo.toml index e557e68fb..870a134b5 100644 --- a/src/uu/echo/Cargo.toml +++ b/src/uu/echo/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/echo.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" } [[bin]] diff --git a/src/uu/echo/src/echo.rs b/src/uu/echo/src/echo.rs index 6f4d2e674..ebf0d46e7 100644 --- a/src/uu/echo/src/echo.rs +++ b/src/uu/echo/src/echo.rs @@ -6,7 +6,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use clap::{crate_version, Arg, Command}; +use clap::{crate_version, Arg, ArgAction, Command}; use std::io::{self, Write}; use std::iter::Peekable; use std::str::Chars; @@ -113,8 +113,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args.collect_lossy(); let matches = uu_app().get_matches_from(args); - let no_newline = matches.contains_id(options::NO_NEWLINE); - let escaped = matches.contains_id(options::ENABLE_BACKSLASH_ESCAPE); + let no_newline = matches.get_flag(options::NO_NEWLINE); + let escaped = matches.get_flag(options::ENABLE_BACKSLASH_ESCAPE); let values: Vec = match matches.get_many::(options::STRING) { Some(s) => s.map(|s| s.to_string()).collect(), None => vec!["".to_string()], @@ -124,7 +124,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .map_err_context(|| "could not write to stdout".to_string()) } -pub fn uu_app<'a>() -> Command<'a> { +pub fn uu_app() -> Command { Command::new(uucore::util_name()) .name(NAME) // TrailingVarArg specifies the final positional argument is a VarArg @@ -141,21 +141,21 @@ pub fn uu_app<'a>() -> Command<'a> { Arg::new(options::NO_NEWLINE) .short('n') .help("do not output the trailing newline") - .takes_value(false), + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::ENABLE_BACKSLASH_ESCAPE) .short('e') .help("enable interpretation of backslash escapes") - .takes_value(false), + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::DISABLE_BACKSLASH_ESCAPE) .short('E') .help("disable interpretation of backslash escapes (default)") - .takes_value(false), + .action(ArgAction::SetTrue), ) - .arg(Arg::new(options::STRING).multiple_occurrences(true)) + .arg(Arg::new(options::STRING).action(ArgAction::Append)) } fn execute(no_newline: bool, escaped: bool, free: &[String]) -> io::Result<()> {