2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
|
|
|
# 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
|
|
|
|
|
|
|
|
####################
|
2017-07-13 13:12:41 +08:00
|
|
|
# No args
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-13 13:12:41 +08:00
|
|
|
# One arg and no matching flags
|
|
|
|
argv help
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-13 13:12:41 +08:00
|
|
|
# Five args with two matching a flag
|
2017-07-21 08:54:06 +08:00
|
|
|
_flag_h '--help' '-h'
|
|
|
|
_flag_help '--help' '-h'
|
2017-07-13 13:12:41 +08:00
|
|
|
argv 'help' 'me' 'a lot more'
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-13 13:12:41 +08:00
|
|
|
# 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'
|
2017-07-21 08:54:06 +08:00
|
|
|
_flag_h --help
|
|
|
|
_flag_help --help
|
2017-07-13 13:12:41 +08:00
|
|
|
argv 'help' 'me'
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-13 13:12:41 +08:00
|
|
|
# --stop-nonopt works
|
|
|
|
_flag_a A2
|
|
|
|
_flag_abc A2
|
2017-07-21 08:54:06 +08:00
|
|
|
_flag_h -h
|
|
|
|
_flag_help -h
|
2017-07-13 13:12:41 +08:00
|
|
|
argv 'non-opt' 'second non-opt' '--help'
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-17 09:27:41 +08:00
|
|
|
# Implicit int flags work
|
2017-07-14 11:36:59 +08:00
|
|
|
_flag_val 123
|
|
|
|
argv 'abc' 'def'
|
|
|
|
_flag_t woohoo
|
|
|
|
_flag_token woohoo
|
2017-07-21 08:54:06 +08:00
|
|
|
_flag_v '-v' '--verbose'
|
2017-07-14 11:36:59 +08:00
|
|
|
_flag_val -234
|
2017-07-21 08:54:06 +08:00
|
|
|
_flag_verbose '-v' '--verbose'
|
2017-07-14 11:36:59 +08:00
|
|
|
argv 'a1' 'a2'
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-17 09:27:41 +08:00
|
|
|
# Should be set to 987
|
|
|
|
_flag_m 987
|
|
|
|
_flag_max 987
|
|
|
|
argv 'argle' 'bargle'
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-17 09:27:41 +08:00
|
|
|
# Should be set to 765
|
|
|
|
_flag_m 765
|
|
|
|
_flag_max 765
|
|
|
|
argv 'argle' 'bargle'
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-22 06:55:52 +08:00
|
|
|
# Bool short flag only
|
|
|
|
_flag_C -C
|
|
|
|
_flag_v '-v' '-v'
|
|
|
|
argv 'arg1' 'arg2'
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-22 06:55:52 +08:00
|
|
|
# Value taking short flag only
|
|
|
|
_flag_v '--verbose' '-v'
|
|
|
|
_flag_verbose '--verbose' '-v'
|
|
|
|
_flag_x arg2
|
|
|
|
argv arg1
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-22 06:55:52 +08:00
|
|
|
# Implicit int short flag only
|
|
|
|
_flag_v '-v' '-v' '-v'
|
|
|
|
_flag_verbose '-v' '-v' '-v'
|
|
|
|
_flag_x 321
|
|
|
|
argv 'argle' 'bargle'
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-22 06:55:52 +08:00
|
|
|
# Implicit int short flag only with custom validation passes
|
|
|
|
_flag_v '-v' '-v' '-v'
|
|
|
|
_flag_verbose '-v' '-v' '-v'
|
|
|
|
_flag_x 499
|
|
|
|
argv
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
|
|
|
# Implicit int short flag only with custom validation fails
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Implicit int flag validation fails
|
|
|
|
|
|
|
|
####################
|
2017-07-17 12:10:22 +08:00
|
|
|
# Check the exit status from argparse validation
|
|
|
|
_flag_name max
|
|
|
|
_flag_value 83
|
|
|
|
expected argparse return status 57
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
|
|
|
# Explicit int flag validation
|
2019-04-27 00:37:24 +08:00
|
|
|
|
|
|
|
####################
|
|
|
|
# Errors use function name by default
|
2019-03-07 02:51:59 +08:00
|
|
|
|
|
|
|
####################
|
|
|
|
# Ignoring unknown options
|
|
|
|
-t tango --wurst
|
|
|
|
alpha aaaa
|
2019-04-29 23:03:16 +08:00
|
|
|
|
|
|
|
####################
|
|
|
|
# Check for crash when last option is unknown
|
2019-05-03 22:20:40 +08:00
|
|
|
|
|
|
|
####################
|
|
|
|
# Checking arguments after --
|
|
|
|
a
|
|
|
|
b
|
|
|
|
-a
|