Added an -S/--strict-longopts option to argparse.

This flag disables a very surprising and confusing feature I found in the code
of wgetopt.rs: the ability to abbreviate the names of long options and the
ability to parse long options with a single "-". This commit addresses #7341,
but unlike pull request #11220, it does so in a backwards compatible way: one
must use the new -S/--strict-longotps flag to disable the old legacy behaviour.

Unlike pull request #11220 however, this flag only applies to ``argparse``,
and not to any builtins used by fish.

Note that forcing the flag -S/--strict-longotps on (i.e. in  src/wgetopt.rs,
replacing both uses of `self.strict_long_opts` with `true`), does not cause any
of the current test cases to fail. However, third-party fish scripts may be
depending on the current behaviour.
This commit is contained in:
Isaac Oscar Gariano
2025-08-03 10:07:08 +10:00
parent 70dca1e136
commit 24eeed65a2
6 changed files with 65 additions and 5 deletions

View File

@@ -645,5 +645,35 @@ argparse a/alpha -- --banna=value
argparse a/alpha -- --alpha=value --banna=value
# CHECKERR: argparse: --alpha=value: option does not take an argument
# Check behaviour without -S/--strict-longopts option
begin
argparse long valu=+ -- --lon -long -lon -valu=3 -valu 4 -val=3 -val 4
set -lL
# CHECK: _flag_long '--long' '--long' '--long'
# CHECK: _flag_valu '3' '4' '3' '4'
# CHECK: argv
# CHECK: argv_opts '--lon' '-long' '-lon' '-valu=3' '-valu' '4' '-val=3' '-val' '4'
argparse amb ambig -- -am
# CHECKERR: argparse: -am: unknown option
argparse a ambig -- -ambig
# CHECKERR: argparse: -ambig: unknown option
argparse long -- -long3
# CHECKERR: argparse: -long3: unknown option
end
# Check behaviour with -S/--strict-longopts option
begin
argparse -S long -- --lon
# CHECKERR: argparse: --lon: unknown option
argparse -S long -- -long
# CHECKERR: argparse: -long: unknown option
argparse --strict-longopts long -- -lon
# CHECKERR: argparse: -lon: unknown option
argparse -S value=+ -- -valu=3
# CHECKERR: argparse: -valu=3: unknown option
argparse --strict-longopts value=+ -- -valu 4
# CHECKERR: argparse: -valu: unknown option
end
# Check that the argparse's are properly wrapped in begin blocks
set -l