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?

give docopt try:

>>> 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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -