Give a more helpful error when a boolean option has an argument.

This fixes an issue very similar to #6483,
For example, fish --login=root used to print this:
    fish: --login=root: unknown option
But `--login` is a valid option to fish.
So the above now prints:
    fish: --login=root: option does not take an argument

This is done by modifying WGetOpter so that it returns a ';' if it encountered
an option with an argument, but the option was not declared as taking an option
(this is only possible with the --long=value or legacy -long=value syntax).
All uses of WGetOpter (except echo, fish_indent, and some tests) are modified to
then print an appropriate error message when ';' is returned.
echo doesn't have any long options, so it will panic if gets a ';'.
fish_indent doesn't print any error messages for invalid options anyway, and I
wasn't sure if this was intentional or not.

Moreover, WGetOpter now always returns a ':' for options that are missing an
argument. And you can no longer prefix a your option spec with a ':' to enable
this (since every use of WGetOpter was doing this anyway, except
wgetopt::test_exchange and tests::wgetopt::test_wgetopt).
This commit is contained in:
Isaac Oscar Gariano
2025-08-19 10:54:43 +10:00
parent c94eddaf4b
commit 70dca1e136
59 changed files with 369 additions and 60 deletions

View File

@@ -639,5 +639,11 @@ begin
# CHECK: argv_opts '-abv124' '-abv125' '-abv124' '-vd3'
end
argparse a/alpha -- --banna=value
# CHECKERR: argparse: --banna=value: unknown option
# But this gives a better message
argparse a/alpha -- --alpha=value --banna=value
# CHECKERR: argparse: --alpha=value: option does not take an argument
# Check that the argparse's are properly wrapped in begin blocks
set -l