Hello I tried Python's docopt (command line argument processing) [^ 1].
In the example below, I tried the difference in the description of --oo
, `--pp```, and` `--qq```. In the case of
`--qq```, the result is returned as a list (this description may not be officially recommended).
$ ./docopt_test.py
{'--help': False,
'--oo': None,
'--pp': None,
'--qq': [],
'X': []}
$
$ ./docopt_test.py -o 0 -p 1 -q 2 3 4
{'--help': False,
'--oo': '0',
'--pp': '1',
'--qq': ['2'],
'X': ['3', '4']}
$
docopt_test.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def argsdocopt(doc):
import docopt, textwrap
return docopt.docopt(textwrap.dedent(doc))
def main():
"""
{f}: Test a docopt library.
usage: {f} [-h] [-o O] [-p <P>|--pp <P>] [-q|--qq <Q>] [X...]
options:
-h, --help show this help message and exit
-o, --oo O parameter O
-p <P>, --pp <P> parameter P
-q, --qq <Q> parameter Q
"""
args = argsdocopt(main.__doc__.format(f=__file__))
print(args)
if __name__ == '__main__':
main()
[^ 1]: I also referred to "Python docopt usage memo".
Recommended Posts