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
This commit is contained in:
Nahor
2026-03-31 18:17:43 -07:00
committed by Johannes Altmanninger
parent 0367aaea7d
commit 2f9c2df10d
3 changed files with 37 additions and 10 deletions

View File

@@ -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
-----------

View File

@@ -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)

View File

@@ -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)