mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #3206 from 353fc443/timeout-empty-string
timeout: avoid panicking for empty string
This commit is contained in:
commit
9113594951
1 changed files with 9 additions and 6 deletions
|
@ -51,7 +51,7 @@ struct Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
fn from(options: &clap::ArgMatches) -> Self {
|
fn from(options: &clap::ArgMatches) -> UResult<Self> {
|
||||||
let signal = match options.value_of(options::SIGNAL) {
|
let signal = match options.value_of(options::SIGNAL) {
|
||||||
Some(signal_) => {
|
Some(signal_) => {
|
||||||
let signal_result = signal_by_name_or_value(signal_);
|
let signal_result = signal_by_name_or_value(signal_);
|
||||||
|
@ -69,8 +69,11 @@ impl Config {
|
||||||
.value_of(options::KILL_AFTER)
|
.value_of(options::KILL_AFTER)
|
||||||
.map(|time| uucore::parse_time::from_str(time).unwrap());
|
.map(|time| uucore::parse_time::from_str(time).unwrap());
|
||||||
|
|
||||||
let duration: Duration =
|
let duration =
|
||||||
uucore::parse_time::from_str(options.value_of(options::DURATION).unwrap()).unwrap();
|
match uucore::parse_time::from_str(options.value_of(options::DURATION).unwrap()) {
|
||||||
|
Ok(duration) => duration,
|
||||||
|
Err(err) => return Err(USimpleError::new(1, err)),
|
||||||
|
};
|
||||||
|
|
||||||
let preserve_status: bool = options.is_present(options::PRESERVE_STATUS);
|
let preserve_status: bool = options.is_present(options::PRESERVE_STATUS);
|
||||||
let foreground = options.is_present(options::FOREGROUND);
|
let foreground = options.is_present(options::FOREGROUND);
|
||||||
|
@ -82,7 +85,7 @@ impl Config {
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Self {
|
Ok(Self {
|
||||||
foreground,
|
foreground,
|
||||||
kill_after,
|
kill_after,
|
||||||
signal,
|
signal,
|
||||||
|
@ -90,7 +93,7 @@ impl Config {
|
||||||
preserve_status,
|
preserve_status,
|
||||||
verbose,
|
verbose,
|
||||||
command,
|
command,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +107,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
|
|
||||||
let matches = app.get_matches_from(args);
|
let matches = app.get_matches_from(args);
|
||||||
|
|
||||||
let config = Config::from(&matches);
|
let config = Config::from(&matches)?;
|
||||||
timeout(
|
timeout(
|
||||||
&config.command,
|
&config.command,
|
||||||
config.duration,
|
config.duration,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue