From 7a07c088606266183527e226bcc86fbdc5fcd4c4 Mon Sep 17 00:00:00 2001 From: Isaac Oscar Gariano Date: Thu, 21 Aug 2025 11:50:25 +1000 Subject: [PATCH] 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 --- doc_src/cmds/function.rst | 2 +- src/function.rs | 3 ++- tests/checks/function-definition.fish | 8 ++++---- tests/checks/function.fish | 8 ++++---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/doc_src/cmds/function.rst b/doc_src/cmds/function.rst index c2be34719..67ac36830 100644 --- a/doc_src/cmds/function.rst +++ b/doc_src/cmds/function.rst @@ -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 `. + 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 `. **-d** *DESCRIPTION* or **--description** *DESCRIPTION* A description of what the function does, suitable as a completion description. diff --git a/src/function.rs b/src/function.rs index e3d71f466..f1c9cb522 100644 --- a/src/function.rs +++ b/src/function.rs @@ -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); } } diff --git a/tests/checks/function-definition.fish b/tests/checks/function-definition.fish index 8c6248bcd..205813fda 100644 --- a/tests/checks/function-definition.fish +++ b/tests/checks/function-definition.fish @@ -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 diff --git a/tests/checks/function.fish b/tests/checks/function.fish index dafbc6c1e..eaa83f93b 100644 --- a/tests/checks/function.fish +++ b/tests/checks/function.fish @@ -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