From b6a4f32889fc53149965d6e4e1a9d9fcf1b36ad8 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sat, 1 Oct 2022 00:11:02 +0200 Subject: [PATCH] stdbuf: update to clap 4 --- src/uu/stdbuf/Cargo.toml | 2 +- src/uu/stdbuf/src/stdbuf.rs | 11 +++++------ tests/by-util/test_stdbuf.rs | 15 ++++----------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/uu/stdbuf/Cargo.toml b/src/uu/stdbuf/Cargo.toml index fe07085bd..89047e446 100644 --- a/src/uu/stdbuf/Cargo.toml +++ b/src/uu/stdbuf/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/stdbuf.rs" [dependencies] -clap = { version = "3.2", features = ["wrap_help", "cargo"] } +clap = { version = "4.0", features = ["wrap_help", "cargo"] } tempfile = "3" uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 1c29d3ceb..f09755628 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -10,7 +10,7 @@ #[macro_use] extern crate uucore; -use clap::{crate_version, Arg, ArgMatches, Command}; +use clap::{crate_version, Arg, ArgAction, ArgMatches, Command}; use std::fs::File; use std::io::{self, Write}; use std::os::unix::process::ExitStatusExt; @@ -162,9 +162,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let options = ProgramOptions::try_from(&matches).map_err(|e| UUsageError::new(125, e.0))?; - let mut command_values = matches.values_of::<&str>(options::COMMAND).unwrap(); + let mut command_values = matches.get_many::(options::COMMAND).unwrap(); let mut command = process::Command::new(command_values.next().unwrap()); - let command_params: Vec<&str> = command_values.collect(); + let command_params: Vec<&str> = command_values.map(|s| s.as_ref()).collect(); let mut tmp_dir = tempdir().unwrap(); let (preload_env, libstdbuf) = get_preload_env(&mut tmp_dir).map_err_context(String::new)?; @@ -193,7 +193,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } } -pub fn uu_app<'a>() -> Command<'a> { +pub fn uu_app() -> Command { Command::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) @@ -227,8 +227,7 @@ pub fn uu_app<'a>() -> Command<'a> { ) .arg( Arg::new(options::COMMAND) - .multiple_occurrences(true) - .takes_value(true) + .action(ArgAction::Append) .hide(true) .required(true) .value_hint(clap::ValueHint::CommandName), diff --git a/tests/by-util/test_stdbuf.rs b/tests/by-util/test_stdbuf.rs index bc723d8e7..344b759db 100644 --- a/tests/by-util/test_stdbuf.rs +++ b/tests/by-util/test_stdbuf.rs @@ -27,17 +27,10 @@ fn test_stdbuf_line_buffered_stdout() { fn test_stdbuf_no_buffer_option_fails() { let ts = TestScenario::new(util_name!()); - ts.ucmd().args(&["head"]).fails().stderr_is(&format!( - "error: The following required arguments were not provided:\n \ - --input \n \ - --output \n \ - --error \n\n\ - USAGE:\n \ - {1} {0} OPTION... COMMAND\n\n\ - For more information try --help", - ts.util_name, - ts.bin_path.to_string_lossy() - )); + ts.ucmd() + .args(&["head"]) + .fails() + .stderr_contains("The following required arguments were not provided:"); } #[cfg(not(target_os = "windows"))]