mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-21 01:04:10 +08:00
argparse: Fix validation for short-only-flags
This read something like `o=!_validate_int`, and the flag modifier reading kept the pointer after the `!`, so it created a long flag called `_validate_int`, which meant it would not only error out form ```fish argparse 'i=!_validate_int' 'o=!_validate_int' -- $argv ``` with "Long flag '_validate_int' already defined", but also set $_flag_validate_int. Fixes #5864.
This commit is contained in:
parent
5bf21f2928
commit
e20c08d04e
@ -181,6 +181,8 @@ static bool parse_flag_modifiers(const argparse_cmd_opts_t &opts, const option_s
|
||||
if (*s == L'!') {
|
||||
s++;
|
||||
opt_spec->validation_command = wcstring(s);
|
||||
// Move cursor to the end so we don't expect a long flag.
|
||||
while (*s) s++;
|
||||
} else if (*s) {
|
||||
streams.err.append_format(BUILTIN_ERR_INVALID_OPT_SPEC, opts.name.c_str(),
|
||||
option_spec.c_str(), *s);
|
||||
|
@ -121,3 +121,8 @@ in function 'notargparse'
|
||||
|
||||
####################
|
||||
# Checking arguments after --
|
||||
|
||||
####################
|
||||
# Checking validation for short flags only
|
||||
argparse: Value 'banana' for flag 'o' is not an integer
|
||||
argparse: Value '-o' for flag 'i' is not an integer
|
||||
|
@ -195,3 +195,12 @@ begin
|
||||
argparse a/alpha -- a --alpha -- b -a
|
||||
printf '%s\n' $argv
|
||||
end
|
||||
|
||||
# #5864 - short flag only with same validation function.
|
||||
logmsg Checking validation for short flags only
|
||||
argparse 'i=!_validate_int' 'o=!_validate_int' -- -i 2 -o banana
|
||||
argparse 'i=!_validate_int' 'o=!_validate_int' -- -i -o banana
|
||||
begin
|
||||
argparse 'i=!_validate_int' 'o=!_validate_int' -- -i 2 -o 3
|
||||
set -l
|
||||
end
|
||||
|
@ -146,3 +146,15 @@ alpha aaaa
|
||||
a
|
||||
b
|
||||
-a
|
||||
|
||||
####################
|
||||
# Checking validation for short flags only
|
||||
_flag_a 'alpha' 'aaaa'
|
||||
_flag_b -b
|
||||
_flag_break -b
|
||||
_flag_i 2
|
||||
_flag_m 1
|
||||
_flag_max 1
|
||||
_flag_o 3
|
||||
argv
|
||||
saved_status 57
|
||||
|
Loading…
x
Reference in New Issue
Block a user