Message121250
| Author |
G2P |
| Recipients |
G2P, bethard, elsdoerfer, eric.araujo, nvie, r.david.murray |
| Date |
2010年11月15日.23:23:49 |
| SpamBayes Score |
1.2695776e-06 |
| Marked as misclassified |
No |
| Message-id |
<1289863431.63.0.271177942267.issue9253@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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
example. |
|