diff --git a/fish-rust/src/builtins/set.rs b/fish-rust/src/builtins/set.rs index 02b754ced..173068d7a 100644 --- a/fish-rust/src/builtins/set.rs +++ b/fish-rust/src/builtins/set.rs @@ -199,7 +199,7 @@ fn parse( 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 @@ fn validate( opts: &Self, cmd: &wstr, args: &[&wstr], + optind: usize, parser: &Parser, streams: &mut IoStreams, ) -> Result<(), Option> { @@ -277,8 +278,10 @@ fn validate( 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); } diff --git a/tests/checks/set.fish b/tests/checks/set.fish index 6d99ecd42..9c4a9ad7e 100644 --- a/tests/checks/set.fish +++ b/tests/checks/set.fish @@ -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