Usage

1
2
# Run empty
!python src.py
1
2
# Run help
!python src.py -h
usage: pytest [-h] {cmd1,cmd2} ...

App Description goes here

optional arguments:
  -h, --help   show this help message and exit

commands:
  {cmd1,cmd2}
    cmd1       Example function with types documented in the docstring.
    cmd2       A script with three optional values.

1
2
# ran `cmd1` help
!python src.py cmd1 -h
usage: pytest cmd1 [-h] [-a {one,two}] [-o OPTIONAL_STR] [-p OPTIONAL_INT]
                   [-t [OPTIONAL_TPL [OPTIONAL_TPL ...]]]
                   an_int an_str a_tuple a_tuple a_tuple a_var_tuple
                   [a_var_tuple ...]

Example function with types documented in the docstring.

positional arguments:
  an_int
  an_str
  a_tuple
  a_var_tuple

optional arguments:
  -h, --help            show this help message and exit
  -a {one,two}, --an-enum {one,two}
  -o OPTIONAL_STR, --optional-str OPTIONAL_STR
  -p OPTIONAL_INT, --optional-int OPTIONAL_INT
  -t [OPTIONAL_TPL [OPTIONAL_TPL ...]], --optional-tpl [OPTIONAL_TPL [OPTIONAL_TPL ...]]

1
2
# ran `cmd1` with only required
!python src.py cmd1 10 str1 tp1 tp2 tp3 vtp1
a_tuple (<class 'tuple'>): ('tp1', 'tp2', 'tp3')
a_var_tuple (<class 'tuple'>): ('vtp1',)
an_enum (<enum 'Choice'>): one
an_int (<class 'int'>): 10
an_str (<class 'str'>): str1
optional_int (<class 'int'>): 0
optional_str (<class 'str'>): 
optional_tpl (<class 'tuple'>): ()

1
2
# ran `cmd1` with valid arguments
!python src.py cmd1 10 str1 tp1 tp2 tp3 vtp1 --optional-tpl otp1 otp2 --optional-tpl otp3 --optional-str ostr --optional-int 100 --an-enum two
a_tuple (<class 'tuple'>): ('tp1', 'tp2', 'tp3')
a_var_tuple (<class 'tuple'>): ('vtp1',)
an_enum (<enum 'Choice'>): two
an_int (<class 'int'>): 10
an_str (<class 'str'>): str1
optional_int (<class 'int'>): 100
optional_str (<class 'str'>): ostr
optional_tpl (<class 'tuple'>): ('otp1', 'otp2', 'otp3')

1
2
# ran `cmd2` help
!python src.py cmd2 -h
usage: pytest cmd2 [-h] [-m] [-y] [--my] [a_list [a_list ...]]

A script with three optional values.

positional arguments:
  a_list       catch all positional arguments (default: None)

optional arguments:
  -h, --help   show this help message and exit
  -m, --m-opt  the m_opt helptext (default: False)
  -y, --y-opt  the y_opt helptext (default: False)
  --my         the my helptext (default: False)

1
2
# ran `cmd2` with args
!python src.py cmd2 10 100 1000
a_list (<class 'list'>): [10, 100, 1000]
m_opt (<class 'bool'>): False
my (<class 'bool'>): False
y_opt (<class 'bool'>): False