[issue9253] argparse: optional subparsers
report at bugs.python.org
Tue Nov 16 00:23:51 CET 2010
G2P <g2p.code+python at gmail.com> added the comment:
Trying to spec this, here is a proposed API:
parser = argparse.ArgumentParser()
sub = parser.add_subparsers(default='show')
sub_show = sub.add_parser('show')
sub_add = sub.add_parser('add')
If default isn't passed, the subcommand isn't optional.
If default is passed, and no explicit subcommand is given,
the default subcommand is picked.
Arguments are given to the top parser; passing arguments
to the subcommand requires naming it explicitly.
As far as motivation, I'd like to change a program that
uses --choice options (that can have a default) to use
more expressive subcommands. Some programs rely on implicit
subcommands a lot; the ip command on linux is a good
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list