mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-12-19 05:05:49 +08:00
Use iterators to clean up disown
logic
This commit is contained in:
parent
c1acbf2845
commit
fea1e3aee5
|
@ -80,37 +80,39 @@ pub fn disown(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> O
|
||||||
retval = STATUS_CMD_ERROR;
|
retval = STATUS_CMD_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut jobs = vec![];
|
|
||||||
|
|
||||||
retval = STATUS_CMD_OK;
|
retval = STATUS_CMD_OK;
|
||||||
|
|
||||||
// If one argument is not a valid pid (i.e. integer >= 0), fail without disowning anything,
|
// If one argument is not a valid pid (i.e. integer >= 0), fail without disowning anything,
|
||||||
// but still print errors for all of them.
|
// but still print errors for all of them.
|
||||||
// Non-existent jobs aren't an error, but information about them is useful.
|
// Non-existent jobs aren't an error, but information about them is useful.
|
||||||
// Multiple PIDs may refer to the same job; include the job only once by using a set.
|
let mut jobs: Vec<_> = args[1..]
|
||||||
for arg in &args[1..] {
|
.iter()
|
||||||
match fish_wcstoi(arg).ok().and_then(Pid::new) {
|
.filter_map(|arg| {
|
||||||
None => {
|
// Attempt to convert the argument to a PID.
|
||||||
streams.err.append(wgettext_fmt!(
|
match fish_wcstoi(arg).ok().and_then(Pid::new) {
|
||||||
"%ls: '%ls' is not a valid job specifier\n",
|
None => {
|
||||||
cmd,
|
// Invalid identifier
|
||||||
arg
|
streams.err.append(wgettext_fmt!(
|
||||||
));
|
"%ls: '%ls' is not a valid job specifier\n",
|
||||||
retval = STATUS_INVALID_ARGS;
|
cmd,
|
||||||
}
|
arg
|
||||||
Some(pid) => {
|
));
|
||||||
if let Some(j) = parser.job_get_from_pid(pid) {
|
retval = STATUS_INVALID_ARGS;
|
||||||
jobs.push(j);
|
None
|
||||||
} else {
|
}
|
||||||
|
Some(pid) => parser.job_get_from_pid(pid).or_else(|| {
|
||||||
|
// Valid identifier but no such job
|
||||||
streams.err.append(wgettext_fmt!(
|
streams.err.append(wgettext_fmt!(
|
||||||
"%ls: Could not find job '%d'\n",
|
"%ls: Could not find job '%d'\n",
|
||||||
cmd,
|
cmd,
|
||||||
pid
|
pid
|
||||||
));
|
));
|
||||||
}
|
None
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
.collect();
|
||||||
|
|
||||||
if retval != STATUS_CMD_OK {
|
if retval != STATUS_CMD_OK {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user