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
:
-
chicken
alone would display the same output than thechicken help
command be returning an error because it requires at least an argument (some command can have default behavior without argument likepwd
) -
chicken sing
would display a chicken song. A song can be specified by adding an argument (ie:chicken sing christmas
for a christmas chicken song -
chicken eat
would return an error because chicken don't eat nothing. One or several argument shall be added (corn
, ...) -
chicken clothes
would display all the clothes the chicken is wearing -
chicken clothes add boots helmet
would allow to allow to add clothes (here boots and helmet) to the chicken -
chicken help clothes
would document theclothes
related 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.