set: Fix set -e without arguments

This didn't actually error out because we passed all of args.

It *might* be cleaner to pass a slice?
This commit is contained in:
Fabian Boehm 2024-01-01 16:21:08 +01:00
parent b895cf49ca
commit 6618ca17f2
2 changed files with 15 additions and 3 deletions

View file

@ -199,7 +199,7 @@ impl Options {
return Err(STATUS_CMD_OK);
}
Self::validate(&opts, cmd, args, parser, streams)?;
Self::validate(&opts, cmd, args, optind, parser, streams)?;
Ok((opts, optind))
}
@ -208,6 +208,7 @@ impl Options {
opts: &Self,
cmd: &wstr,
args: &[&wstr],
optind: usize,
parser: &Parser,
streams: &mut IoStreams,
) -> Result<(), Option<c_int>> {
@ -277,8 +278,10 @@ impl Options {
return Err(STATUS_INVALID_ARGS);
}
if args.is_empty() && opts.erase {
streams.err.append(wgettext_fmt!(BUILTIN_ERR_MISSING, cmd));
if args.len() == optind && opts.erase {
streams
.err
.append(wgettext_fmt!(BUILTIN_ERR_MISSING, cmd, L!("--erase")));
builtin_print_error_trailer(parser, streams.err, cmd);
return Err(STATUS_INVALID_ARGS);
}

View file

@ -938,3 +938,12 @@ begin
end
echo $secret
# CHECK: global 4 23 42
set -e
# CHECKERR: set: --erase: option requires an argument
# CHECKERR: {{.*}}set.fish (line {{\d+}}):
# CHECKERR: set -e
# CHECKERR: ^
# CHECKERR: (Type 'help set' for related documentation)
exit 0