MCPcopy Create free account
hub / github.com/PlatformLab/NanoLog / docopt

Function docopt

preprocessor/docopt.py:490–581  ·  view source on GitHub ↗

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, , commands, which could be [optional], (required), (mutually |

(doc, argv=None, help=True, version=None, options_first=False)

Source from the content-addressed store, hash-verified

488
489
490def docopt(doc, argv=None, help=True, version=None, options_first=False):
491 """Parse `argv` based on command-line interface described in `doc`.
492
493 `docopt` creates your command-line interface based on its
494 description that you pass as `doc`. Such description can contain
495 --options, <positional-argument>, commands, which could be
496 [optional], (required), (mutually | exclusive) or repeated...
497
498 Parameters
499 ----------
500 doc : str
501 Description of your command-line interface.
502 argv : list of str, optional
503 Argument vector to be parsed. sys.argv[1:] is used if not
504 provided.
505 help : bool (default: True)
506 Set to False to disable automatic help on -h or --help
507 options.
508 version : any object
509 If passed, the object will be printed if --version is in
510 `argv`.
511 options_first : bool (default: False)
512 Set to True to require options precede positional arguments,
513 i.e. to forbid options and positional arguments intermix.
514
515 Returns
516 -------
517 args : dict
518 A dictionary, where keys are names of command-line elements
519 such as e.g. "--verbose" and "<path>", and values are the
520 parsed values of those elements.
521
522 Example
523 -------
524 >>> from docopt import docopt
525 >>> doc = ''&#x27;
526 ... Usage:
527 ... my_program tcp <host> <port> [--timeout=<seconds>]
528 ... my_program serial <port> [--baud=<n>] [--timeout=<seconds>]
529 ... my_program (-h | --help | --version)
530 ...
531 ... Options:
532 ... -h, --help Show this screen and exit.
533 ... --baud=<n> Baudrate [default: 9600]
534 ... ''&#x27;
535 >>> argv = ['tcp', '127.0.0.1', '80', '--timeout', '30']
536 >>> docopt(doc, argv)
537 {'--baud': '9600',
538 '--help': False,
539 '--timeout': '30',
540 '--version': False,
541 '<host>': '127.0.0.1',
542 '<port>': '80',
543 'serial': False,
544 'tcp': True}
545
546 See also
547 --------

Callers 1

parser.pyFile · 0.90

Calls 13

parse_sectionFunction · 0.85
DocoptLanguageErrorClass · 0.85
parse_defaultsFunction · 0.85
parse_patternFunction · 0.85
formal_usageFunction · 0.85
parse_argvFunction · 0.85
TokensClass · 0.85
extrasFunction · 0.85
DictClass · 0.85
DocoptExitClass · 0.85
fixMethod · 0.80
flatMethod · 0.45

Tested by

no test coverage detected