From 2f9c2df10ddd06a6e51d7016ce688ff6f6fde12d Mon Sep 17 00:00:00 2001 From: Nahor Date: Tue, 31 Mar 2026 18:17:43 -0700 Subject: [PATCH] set: report an error when called with `-a`,`-p` and no `NAME` Previously executing `set -a` or `set -p` would just list all the variables, which does not make sense since the user specifically ask for an action (append/prepend). Update the help page synopsis Part of #12603 --- doc_src/cmds/set.rst | 17 +++++++++-------- src/builtins/set.rs | 4 ++-- tests/checks/set.fish | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/doc_src/cmds/set.rst b/doc_src/cmds/set.rst index b5ca41c4a..d73f47102 100644 --- a/doc_src/cmds/set.rst +++ b/doc_src/cmds/set.rst @@ -6,16 +6,17 @@ Synopsis .. synopsis:: - set - set (-f | --function) (-l | --local) (-g | --global) (-U | --universal) [--no-event] - set [-Uflg] NAME [VALUE ...] - set [-Uflg] NAME[[INDEX ...]] [VALUE ...] - set (-x | --export) (-u | --unexport) [-Uflg] NAME [VALUE ...] - set (-a | --append) (-p | --prepend) [-Uflg] NAME VALUE ... - set (-e | --erase) [-Uflg] [-xu] [NAME][[INDEX]] ...] - set (-q | --query) [-Uflg] [-xu] [NAME][[INDEX]] ...] + set [(-f | --function) (-l | --local) (-g | --global) (-U | --universal)] + [(-x | --export) (-u | --unexport)] set (-S | --show) (-L | --long) [NAME ...] + set [-Uflg] [-xu] [--no-event] NAME [VALUE ...] + set [-Uflg] [--no-event] NAME[[INDEX ...]] [VALUE ...] + set (-a | --append) (-p | --prepend) [-Uflg] [--no-event] NAME VALUE ... + set (-e | --erase) [-Uflg] [--no-event] NAME[[INDEX]] ... + + set (-q | --query) [-Uflg] [-xu] NAME[[INDEX]] ... + Description ----------- diff --git a/src/builtins/set.rs b/src/builtins/set.rs index 5a8910395..f0183defa 100644 --- a/src/builtins/set.rs +++ b/src/builtins/set.rs @@ -945,7 +945,7 @@ fn set_internal( if argv.is_empty() { streams .err - .appendln(&wgettext_fmt!(BUILTIN_ERR_MIN_ARG_COUNT1, cmd, 1)); + .appendln(&wgettext_fmt!(BUILTIN_ERR_MIN_ARG_COUNT1, cmd, 1, 0)); builtin_print_error_trailer(parser, streams.err, cmd); return Err(STATUS_INVALID_ARGS); } @@ -1045,7 +1045,7 @@ pub fn set(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Buil list(&opts, parser, streams) } else if opts.show { show(cmd, parser, streams, args) - } else if args.is_empty() { + } else if args.is_empty() && !(opts.append || opts.prepend) { list(&opts, parser, streams) } else { set_internal(cmd, &opts, parser, streams, args) diff --git a/tests/checks/set.fish b/tests/checks/set.fish index cda623520..25fe71a99 100644 --- a/tests/checks/set.fish +++ b/tests/checks/set.fish @@ -625,6 +625,19 @@ set --show var5 #CHECK: $var5[7]: |x| #CHECK: $var5[8]: |0| +set -a +# CHECKERR: set: expected >= 1 arguments; got 0 +# CHECKERR: {{.*}}checks/set.fish (line {{\d+}}): +# CHECKERR: set -a +# CHECKERR: ^ +# CHECKERR: (Type 'help set' for related documentation) +set -p +# CHECKERR: set: expected >= 1 arguments; got 0 +# CHECKERR: {{.*}}checks/set.fish (line {{\d+}}): +# CHECKERR: set -p +# CHECKERR: ^ +# CHECKERR: (Type 'help set' for related documentation) + # Setting local scope when no local scope of the var uses the closest scope set -g var6 ghi jkl begin @@ -676,6 +689,19 @@ env | grep TESTVAR | sort | cat -v #CHECK: TESTVAR1=a #CHECK: TESTVAR2=a b +set -x | grep TESTVAR | sort | cat -v +#CHECK: TESTVAR0 +#CHECK: TESTVAR1 a +#CHECK: TESTVAR2 'a' 'b' + +set -u TESTVAR0 +set -u TESTVAR2 a b +set -u | grep TESTVAR | sort | cat -v +#CHECK: TESTVAR0 +#CHECK: TESTVAR2 'a' 'b' +set -x | grep TESTVAR | sort | cat -v +#CHECK: TESTVAR1 a + # if/for/while scope function test_ifforwhile_scope if set -l ifvar1 (true && echo val1)