mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-30 03:01:15 -03:00
fix argparse handling of short flag only specs
@faho noticed that option specs which don't have a long flag name are not handled correctly. This fixes that and adds unit tests. Fixes #4232
This commit is contained in:
@@ -29,6 +29,8 @@ argparse: Long flag 'short' already defined
|
||||
argparse: Implicit int flag '#' already defined
|
||||
# Defining an implicit int flag with modifiers
|
||||
argparse: Implicit int short flag 'v' does not allow modifiers like '='
|
||||
# Implicit int short flag only with custom validation fails
|
||||
argparse: Value '499' for flag 'x' less than min allowed of '500'
|
||||
# Implicit int flag validation fails
|
||||
argparse: Value '765x' for flag 'max' is not an integer
|
||||
argparse: Value 'a1' for flag 'm' is not an integer
|
||||
|
||||
@@ -86,15 +86,42 @@ set -l
|
||||
for v in (set -l -n); set -e $v; end
|
||||
argparse 'v/verbose' '#-val' 't/token=' -- -123 a1 --token woohoo --234 -v a2 --verbose
|
||||
set -l
|
||||
|
||||
echo '# Should be set to 987'
|
||||
for v in (set -l -n); set -e $v; end
|
||||
argparse 'm#max' -- argle -987 bargle
|
||||
set -l
|
||||
|
||||
echo '# Should be set to 765'
|
||||
for v in (set -l -n); set -e $v; end
|
||||
argparse 'm#max' -- argle -987 bargle --max 765
|
||||
set -l
|
||||
|
||||
echo '# Bool short flag only'
|
||||
for v in (set -l -n); set -e $v; end
|
||||
argparse 'C' 'v' -- -C -v arg1 -v arg2
|
||||
set -l
|
||||
|
||||
echo '# Value taking short flag only'
|
||||
for v in (set -l -n); set -e $v; end
|
||||
argparse 'x=' 'v/verbose' -- --verbose arg1 -v -x arg2
|
||||
set -l
|
||||
|
||||
echo '# Implicit int short flag only'
|
||||
for v in (set -l -n); set -e $v; end
|
||||
argparse 'x#' 'v/verbose' -- -v -v argle -v -x 321 bargle
|
||||
set -l
|
||||
|
||||
echo '# Implicit int short flag only with custom validation passes'
|
||||
for v in (set -l -n); set -e $v; end
|
||||
argparse 'x#!_validate_int --max 500' 'v/verbose' -- -v -v -x 499 -v
|
||||
set -l
|
||||
|
||||
echo '# Implicit int short flag only with custom validation fails' >&2
|
||||
for v in (set -l -n); set -e $v; end
|
||||
argparse 'x#!_validate_int --min 500' 'v/verbose' -- -v -v -x 499 -v
|
||||
set -l
|
||||
|
||||
##########
|
||||
# Verify that flag value validation works.
|
||||
|
||||
|
||||
@@ -38,6 +38,25 @@ argv 'argle' 'bargle'
|
||||
_flag_m 765
|
||||
_flag_max 765
|
||||
argv 'argle' 'bargle'
|
||||
# Bool short flag only
|
||||
_flag_C -C
|
||||
_flag_v '-v' '-v'
|
||||
argv 'arg1' 'arg2'
|
||||
# Value taking short flag only
|
||||
_flag_v '--verbose' '-v'
|
||||
_flag_verbose '--verbose' '-v'
|
||||
_flag_x arg2
|
||||
argv arg1
|
||||
# Implicit int short flag only
|
||||
_flag_v '-v' '-v' '-v'
|
||||
_flag_verbose '-v' '-v' '-v'
|
||||
_flag_x 321
|
||||
argv 'argle' 'bargle'
|
||||
# Implicit int short flag only with custom validation passes
|
||||
_flag_v '-v' '-v' '-v'
|
||||
_flag_verbose '-v' '-v' '-v'
|
||||
_flag_x 499
|
||||
argv
|
||||
# Check the exit status from argparse validation
|
||||
_flag_name max
|
||||
_flag_value 83
|
||||
|
||||
Reference in New Issue
Block a user