argparse
argparse copied to clipboard
subcommand support
I think Git-like subcommand can be done by inserting a positional argument and dispatch on subparsers. But this is something argparse should provide directly, with add_subparsers, for example.
I would use argparse as soon as it implement this feature!
I found mention to subcommand in this PR: https://github.com/p-ranav/argparse/pull/21
Is is already working?
Is is already working?
No, needs more time to design. Or you can give some suggestions on how it should behave ("reverse engineering" Python argparse is lots of work).
Regarding the behavior, I think the number of subcommand shall be unlimited.
The behavior should be the same at every command level.
Let's take an example with a imaginary command called chicken:
chickenalone would display the same output than thechicken helpcommand be returning an error because it requires at least an argument (some command can have default behavior without argument likepwd)chicken singwould display a chicken song. A song can be specified by adding an argument (ie:chicken sing christmasfor a christmas chicken songchicken eatwould return an error because chicken don't eat nothing. One or several argument shall be added (corn, ...)chicken clotheswould display all the clothes the chicken is wearingchicken clothes add boots helmetwould allow to allow to add clothes (here boots and helmet) to the chickenchicken help clotheswould document theclothesrelated commands
Each command at its level should allow modifier argument (ie: --no-color, --verbose, --dry-run`).
For example the --verbose could be global, but the --dry-run could be specific to the chicken clothes add command.
It is a list of use case. Hope it helps!
This enhancement has not yet been implemented?
Added support for subcommands.