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

timeout: update to clap 4

This commit is contained in:
Terts Diepraam 2022-10-01 11:06:39 +02:00
parent 72d7287b11
commit 86cbdbb19e
2 changed files with 30 additions and 22 deletions

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/timeout.rs" path = "src/timeout.rs"
[dependencies] [dependencies]
clap = { version = "3.2", features = ["wrap_help", "cargo"] } clap = { version = "4.0", features = ["wrap_help", "cargo"] }
libc = "0.2.135" libc = "0.2.135"
nix = { version = "0.25", default-features = false, features = ["signal"] } nix = { version = "0.25", default-features = false, features = ["signal"] }
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["process", "signals"] } uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["process", "signals"] }

View file

@ -14,7 +14,7 @@ extern crate uucore;
extern crate clap; extern crate clap;
use crate::status::ExitStatus; use crate::status::ExitStatus;
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, ArgAction, Command};
use std::io::ErrorKind; use std::io::ErrorKind;
use std::process::{self, Child, Stdio}; use std::process::{self, Child, Stdio};
use std::time::Duration; use std::time::Duration;
@ -83,9 +83,9 @@ impl Config {
Err(err) => return Err(UUsageError::new(ExitStatus::TimeoutFailed.into(), err)), Err(err) => return Err(UUsageError::new(ExitStatus::TimeoutFailed.into(), err)),
}; };
let preserve_status: bool = options.contains_id(options::PRESERVE_STATUS); let preserve_status: bool = options.get_flag(options::PRESERVE_STATUS);
let foreground = options.contains_id(options::FOREGROUND); let foreground = options.get_flag(options::FOREGROUND);
let verbose = options.contains_id(options::VERBOSE); let verbose = options.get_flag(options::VERBOSE);
let command = options let command = options
.get_many::<String>(options::COMMAND) .get_many::<String>(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") Command::new("timeout")
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
@ -131,43 +131,51 @@ pub fn uu_app<'a>() -> Command<'a> {
.arg( .arg(
Arg::new(options::FOREGROUND) Arg::new(options::FOREGROUND)
.long(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(
Arg::new(options::KILL_AFTER) Arg::new(options::KILL_AFTER)
.long(options::KILL_AFTER) .long(options::KILL_AFTER)
.short('k') .short('k')
.help("also send a KILL signal if COMMAND is still running this long after the initial signal was sent") .help(
.takes_value(true)) "also send a KILL signal if COMMAND is still running this long \
after the initial signal was sent",
),
)
.arg( .arg(
Arg::new(options::PRESERVE_STATUS) Arg::new(options::PRESERVE_STATUS)
.long(options::PRESERVE_STATUS) .long(options::PRESERVE_STATUS)
.help("exit with the same status as COMMAND, even when the command times out") .help("exit with the same status as COMMAND, even when the command times out")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::SIGNAL) Arg::new(options::SIGNAL)
.short('s') .short('s')
.long(options::SIGNAL) .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") .help(
.takes_value(true) "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(
Arg::new(options::VERBOSE) Arg::new(options::VERBOSE)
.short('v') .short('v')
.long(options::VERBOSE) .long(options::VERBOSE)
.help("diagnose to stderr any signal sent upon timeout") .help("diagnose to stderr any signal sent upon timeout")
) .action(ArgAction::SetTrue),
.arg(
Arg::new(options::DURATION)
.index(1)
.required(true)
) )
.arg(Arg::new(options::DURATION).required(true))
.arg( .arg(
Arg::new(options::COMMAND) Arg::new(options::COMMAND)
.index(2)
.required(true) .required(true)
.multiple_occurrences(true) .action(ArgAction::Append)
.value_hint(clap::ValueHint::CommandName) .value_hint(clap::ValueHint::CommandName),
) )
.trailing_var_arg(true) .trailing_var_arg(true)
.infer_long_args(true) .infer_long_args(true)