parsing - Python: argument parser that handles global options to sub-commands properly -
argparse fails @ dealing sub-commands receiving global options:
import argparse p = argparse.argumentparser() p.add_argument('--arg', action='store_true') s = p.add_subparsers() s.add_parser('test') will have p.parse_args('--arg test'.split()) work,
fails on p.parse_args('test --arg'.split()).
anyone aware of python argument parser handles global options sub-commands properly?
>>> docopt import docopt >>> usage = """ ... usage: prog.py command [--test] ... prog.py [--test] ... ... --test perform test.""" >>> docopt(usage, argv='command --test') {'--test': true, 'another': false, 'command': true} >>> docopt(usage, argv='--test command') {'--test': true, 'another': false, 'command': true}
Comments
Post a Comment