From 6618ca17f2dc2536dd7268f2b93a80917433ae39 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Mon, 1 Jan 2024 16:21:08 +0100 Subject: [PATCH] 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? --- fish-rust/src/builtins/set.rs | 9 ++++++--- tests/checks/set.fish | 9 +++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) 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 @@ 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> { @@ -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); } 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