Output function argument-names in one group.

This makes it so that printing a function definition will only use one
--argument-names group, instead of one for argument name.
For example, "function foo -a x y; ..." will print with "function foo
--argument-names x y" instead of "function foo --argument-names x
--argument-names y", which is very bizarre.

Moreover, the documentation no longer says that argument-names "Has to
be the last option.". This sentence appears to have been introduced in
error by pull #10524, since the ability to have options afterwards was
deliberately added by pull #6188.

Part of #11780
This commit is contained in:
Isaac Oscar Gariano
2025-08-21 11:50:25 +10:00
committed by Johannes Altmanninger
parent 1cf110d083
commit 7a07c08860
4 changed files with 11 additions and 10 deletions

View File

@@ -21,7 +21,7 @@ A function is a list of commands that will be executed when the name of the func
The following options are available:
**-a** *NAMES* or **--argument-names** *NAMES*
Has to be the last option. Assigns the value of successive command-line arguments to the names given in *NAMES* (separated by space). These are the same arguments given in :envvar:`argv`, and are still available there. See also :ref:`Argument Handling <variables-argv>`.
Assigns the value of successive command-line arguments to the names given in *NAMES* (separated by space). These are the same arguments given in :envvar:`argv`, and are still available there. See also :ref:`Argument Handling <variables-argv>`.
**-d** *DESCRIPTION* or **--description** *DESCRIPTION*
A description of what the function does, suitable as a completion description.

View File

@@ -475,8 +475,9 @@ pub fn annotated_definition(&self, name: &wstr) -> WString {
let named = &self.named_arguments;
if !named.is_empty() {
sprintf!(=> &mut out, " --argument-names");
for name in named {
sprintf!(=> &mut out, " --argument-names %s", name);
sprintf!(=> &mut out, " %s", name);
}
}

View File

@@ -8,7 +8,7 @@ end
functions stuff
#CHECK: # Defined in {{.*}}
#CHECK: function stuff --argument-names a --argument-names b --argument-names c
#CHECK: function stuff --argument-names a b c
#CHECK: # This is a comment
#CHECK: echo stuff
#CHECK: # This is another comment
@@ -26,10 +26,10 @@ end
functions commenting
#CHECK: # Defined in {{.*}}
#CHECK: function commenting
#CHECK:
#CHECK:
#CHECK: # line 2
#CHECK:
#CHECK:
#CHECK: # line 4
#CHECK:
#CHECK:
#CHECK: echo Bye bye says line 6
#CHECK: end

View File

@@ -108,16 +108,16 @@ test "$name3[3..-1]" = "$name3a[3..-1]"; and echo "3 = 3a"
# Test the first two lines.
string join \n -- $name1[1..2]
#CHECK: # Defined in {{(?:(?!, copied).)*}}
#CHECK: function name1 --argument-names arg1 --argument-names arg2
#CHECK: function name1 --argument-names arg1 arg2
string join \n -- $name1a[1..2]
#CHECK: # Defined in {{.*}}, copied in {{.*}}
#CHECK: function name1a --argument-names arg1 --argument-names arg2
#CHECK: function name1a --argument-names arg1 arg2
string join \n -- $name3[1..2]
#CHECK: # Defined in {{(?:(?!, copied).)*}}
#CHECK: function name3 --argument-names arg1 --argument-names arg2
#CHECK: function name3 --argument-names arg1 arg2
string join \n -- $name3a[1..2]
#CHECK: # Defined in {{.*}}, copied in {{.*}}
#CHECK: function name3a --argument-names arg1 --argument-names arg2
#CHECK: function name3a --argument-names arg1 arg2
function test
echo banana