Parse argv based on command-line interface described in doc.
docopt creates your command-line interface based on its description that you pass as doc. Such description can contain –options, <positional-argument>, commands, which could be [optional], (required), (mutually | exclusive) or repeated...
>>> from docopt import docopt
>>> doc = '''
Usage:
my_program tcp <host> <port> [--timeout=<seconds>]
my_program serial <port> [--baud=<n>] [--timeout=<seconds>]
my_program (-h | --help | --version)
-h, --help | Show this screen and exit. |
--baud=<n> | Baudrate [default: 9600] |
‘’’ >>> argv = [‘tcp’, ‘127.0.0.1’, ‘80’, ‘–timeout’, ‘30’] >>> docopt(doc, argv) {‘–baud’: ‘9600’,
‘–help’: False, ‘–timeout’: ‘30’, ‘–version’: False, ‘<host>’: ‘127.0.0.1’, ‘<port>’: ‘80’, ‘serial’: False, ‘tcp’: True}