2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-13 13:12:41 +08:00
|
|
|
# No args is an error
|
|
|
|
argparse: No option specs were provided
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-13 13:12:41 +08:00
|
|
|
# Missing -- is an error
|
|
|
|
argparse: Missing -- separator
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-13 13:12:41 +08:00
|
|
|
# Flags but no option specs is an error
|
|
|
|
argparse: No option specs were provided
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-13 13:12:41 +08:00
|
|
|
# Invalid option specs
|
|
|
|
argparse: Invalid option spec 'h-' at char '-'
|
2017-07-14 11:36:59 +08:00
|
|
|
argparse: Short flag '+' invalid, must be alphanum or '#'
|
2017-07-13 13:12:41 +08:00
|
|
|
argparse: Invalid option spec 'h/help:' at char ':'
|
|
|
|
argparse: Invalid option spec 'h-help::' at char ':'
|
|
|
|
argparse: Invalid option spec 'h-help=x' at char 'x'
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-13 13:12:41 +08:00
|
|
|
# --max-args and --min-args work
|
|
|
|
min-max: Expected at least 1 args, got only 0
|
|
|
|
min-max: Expected at most 3 args, got 4
|
|
|
|
min-max: Expected at most 1 args, got 2
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-14 11:36:59 +08:00
|
|
|
# Invalid "#-val" spec
|
2017-07-17 09:27:41 +08:00
|
|
|
argparse: Implicit int short flag '#' does not allow modifiers like '='
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-14 11:36:59 +08:00
|
|
|
# Invalid arg in the face of a "#-val" spec
|
|
|
|
argparse: Unknown option '-x'
|
2017-09-09 12:14:26 +08:00
|
|
|
Standard input (line 41):
|
|
|
|
argparse '#-val' -- abc -x def
|
|
|
|
^
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-17 09:27:41 +08:00
|
|
|
# Defining a short flag more than once
|
|
|
|
argparse: Short flag 's' already defined
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-17 09:27:41 +08:00
|
|
|
# Defining a long flag more than once
|
|
|
|
argparse: Long flag 'short' already defined
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-17 09:27:41 +08:00
|
|
|
# Defining an implicit int flag more than once
|
|
|
|
argparse: Implicit int flag '#' already defined
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-17 09:27:41 +08:00
|
|
|
# Defining an implicit int flag with modifiers
|
|
|
|
argparse: Implicit int short flag 'v' does not allow modifiers like '='
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
|
|
|
# No args
|
|
|
|
|
|
|
|
####################
|
|
|
|
# One arg and no matching flags
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Five args with two matching a flag
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Required, optional, and multiple flags
|
|
|
|
|
|
|
|
####################
|
|
|
|
# --stop-nonopt works
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Implicit int flags work
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Should be set to 987
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Should be set to 765
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Bool short flag only
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Value taking short flag only
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Implicit int short flag only
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Implicit int short flag only with custom validation passes
|
|
|
|
|
|
|
|
####################
|
2017-07-22 06:55:52 +08:00
|
|
|
# Implicit int short flag only with custom validation fails
|
|
|
|
argparse: Value '499' for flag 'x' less than min allowed of '500'
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
2017-07-17 12:10:22 +08:00
|
|
|
# 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
|
2017-08-05 02:39:43 +08:00
|
|
|
|
|
|
|
####################
|
|
|
|
# Check the exit status from argparse validation
|
|
|
|
|
|
|
|
####################
|
2017-07-17 12:10:22 +08:00
|
|
|
# Explicit int flag validation
|
|
|
|
argparse: Value '2' for flag 'm' greater than max allowed of '1'
|
|
|
|
argparse: Value '-1' for flag 'max' less than min allowed of '0'
|