From 86cbdbb19ecb0621781bb96ae28af89f30218b36 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sat, 1 Oct 2022 11:06:39 +0200 Subject: [PATCH] timeout: update to clap 4 --- src/uu/timeout/Cargo.toml | 2 +- src/uu/timeout/src/timeout.rs | 50 ++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/uu/timeout/Cargo.toml b/src/uu/timeout/Cargo.toml index c963dd96e..77adcfe57 100644 --- a/src/uu/timeout/Cargo.toml +++ b/src/uu/timeout/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" path = "src/timeout.rs" [dependencies] -clap = { version = "3.2", features = ["wrap_help", "cargo"] } +clap = { version = "4.0", features = ["wrap_help", "cargo"] } libc = "0.2.135" nix = { version = "0.25", default-features = false, features = ["signal"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["process", "signals"] } diff --git a/src/uu/timeout/src/timeout.rs b/src/uu/timeout/src/timeout.rs index c761ed1d0..8689926c8 100644 --- a/src/uu/timeout/src/timeout.rs +++ b/src/uu/timeout/src/timeout.rs @@ -14,7 +14,7 @@ extern crate uucore; extern crate clap; use crate::status::ExitStatus; -use clap::{crate_version, Arg, Command}; +use clap::{crate_version, Arg, ArgAction, Command}; use std::io::ErrorKind; use std::process::{self, Child, Stdio}; use std::time::Duration; @@ -83,9 +83,9 @@ impl Config { Err(err) => return Err(UUsageError::new(ExitStatus::TimeoutFailed.into(), err)), }; - let preserve_status: bool = options.contains_id(options::PRESERVE_STATUS); - let foreground = options.contains_id(options::FOREGROUND); - let verbose = options.contains_id(options::VERBOSE); + let preserve_status: bool = options.get_flag(options::PRESERVE_STATUS); + let foreground = options.get_flag(options::FOREGROUND); + let verbose = options.get_flag(options::VERBOSE); let command = options .get_many::(options::COMMAND) @@ -123,7 +123,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { ) } -pub fn uu_app<'a>() -> Command<'a> { +pub fn uu_app() -> Command { Command::new("timeout") .version(crate_version!()) .about(ABOUT) @@ -131,43 +131,51 @@ pub fn uu_app<'a>() -> Command<'a> { .arg( Arg::new(options::FOREGROUND) .long(options::FOREGROUND) - .help("when not running timeout directly from a shell prompt, allow COMMAND to read from the TTY and get TTY signals; in this mode, children of COMMAND will not be timed out") + .help( + "when not running timeout directly from a shell prompt, allow \ + COMMAND to read from the TTY and get TTY signals; in this mode, \ + children of COMMAND will not be timed out", + ) + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::KILL_AFTER) .long(options::KILL_AFTER) .short('k') - .help("also send a KILL signal if COMMAND is still running this long after the initial signal was sent") - .takes_value(true)) + .help( + "also send a KILL signal if COMMAND is still running this long \ + after the initial signal was sent", + ), + ) .arg( Arg::new(options::PRESERVE_STATUS) .long(options::PRESERVE_STATUS) .help("exit with the same status as COMMAND, even when the command times out") + .action(ArgAction::SetTrue), ) .arg( Arg::new(options::SIGNAL) .short('s') .long(options::SIGNAL) - .help("specify the signal to be sent on timeout; SIGNAL may be a name like 'HUP' or a number; see 'kill -l' for a list of signals") - .takes_value(true) + .help( + "specify the signal to be sent on timeout; SIGNAL may be a name like \ + 'HUP' or a number; see 'kill -l' for a list of signals", + ) + .value_name("SIGNAL"), ) .arg( Arg::new(options::VERBOSE) - .short('v') - .long(options::VERBOSE) - .help("diagnose to stderr any signal sent upon timeout") - ) - .arg( - Arg::new(options::DURATION) - .index(1) - .required(true) + .short('v') + .long(options::VERBOSE) + .help("diagnose to stderr any signal sent upon timeout") + .action(ArgAction::SetTrue), ) + .arg(Arg::new(options::DURATION).required(true)) .arg( Arg::new(options::COMMAND) - .index(2) .required(true) - .multiple_occurrences(true) - .value_hint(clap::ValueHint::CommandName) + .action(ArgAction::Append) + .value_hint(clap::ValueHint::CommandName), ) .trailing_var_arg(true) .infer_long_args(true)