mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-12-12 00:03:39 +08:00
8c9359fdd4
This keeps all unknown options in $argv, so ```fish argparse -i a/alpha -- -a banana -o val -w ``` results in $_flag_a set to banana, and $argv set to `-o val -w`. This allows users to use multiple argparse passes, or to simply avoid specifying all options e.g. in completions - `systemctl` has 46 of them, most not having any effect on the completions. Fixes #5367.
140 lines
2.5 KiB
Plaintext
140 lines
2.5 KiB
Plaintext
|
|
####################
|
|
# No args is an error
|
|
|
|
####################
|
|
# Missing -- is an error
|
|
|
|
####################
|
|
# Flags but no option specs is an error
|
|
|
|
####################
|
|
# Invalid option specs
|
|
|
|
####################
|
|
# --max-args and --min-args work
|
|
|
|
####################
|
|
# Invalid "#-val" spec
|
|
|
|
####################
|
|
# Invalid arg in the face of a "#-val" spec
|
|
|
|
####################
|
|
# Defining a short flag more than once
|
|
|
|
####################
|
|
# Defining a long flag more than once
|
|
|
|
####################
|
|
# Defining an implicit int flag more than once
|
|
|
|
####################
|
|
# Defining an implicit int flag with modifiers
|
|
|
|
####################
|
|
# No args
|
|
|
|
####################
|
|
# One arg and no matching flags
|
|
argv help
|
|
|
|
####################
|
|
# Five args with two matching a flag
|
|
_flag_h '--help' '-h'
|
|
_flag_help '--help' '-h'
|
|
argv 'help' 'me' 'a lot more'
|
|
|
|
####################
|
|
# Required, optional, and multiple flags
|
|
_flag_a ABC
|
|
_flag_abc ABC
|
|
_flag_d
|
|
_flag_def
|
|
_flag_g 'g1' 'g2' 'g3'
|
|
_flag_ghk 'g1' 'g2' 'g3'
|
|
_flag_h --help
|
|
_flag_help --help
|
|
argv 'help' 'me'
|
|
|
|
####################
|
|
# --stop-nonopt works
|
|
_flag_a A2
|
|
_flag_abc A2
|
|
_flag_h -h
|
|
_flag_help -h
|
|
argv 'non-opt' 'second non-opt' '--help'
|
|
|
|
####################
|
|
# Implicit int flags work
|
|
_flag_val 123
|
|
argv 'abc' 'def'
|
|
_flag_t woohoo
|
|
_flag_token woohoo
|
|
_flag_v '-v' '--verbose'
|
|
_flag_val -234
|
|
_flag_verbose '-v' '--verbose'
|
|
argv 'a1' 'a2'
|
|
|
|
####################
|
|
# Should be set to 987
|
|
_flag_m 987
|
|
_flag_max 987
|
|
argv 'argle' 'bargle'
|
|
|
|
####################
|
|
# Should be set to 765
|
|
_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
|
|
|
|
####################
|
|
# Implicit int short flag only with custom validation fails
|
|
|
|
####################
|
|
# Implicit int flag validation fails
|
|
|
|
####################
|
|
# Check the exit status from argparse validation
|
|
_flag_name max
|
|
_flag_value 83
|
|
expected argparse return status 57
|
|
|
|
####################
|
|
# Explicit int flag validation
|
|
|
|
####################
|
|
# Errors use function name by default
|
|
|
|
####################
|
|
# Ignoring unknown options
|
|
-t tango --wurst
|
|
alpha aaaa
|