argparse icon indicating copy to clipboard operation
argparse copied to clipboard

subcommand support

Open zhihaoy opened this issue 4 years ago • 4 comments

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.

zhihaoy avatar Nov 12 '19 19:11 zhihaoy

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?

MartinDelille avatar Jan 02 '20 08:01 MartinDelille

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

lichray avatar Jan 10 '20 14:01 lichray

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 the chicken help command be returning an error because it requires at least an argument (some command can have default behavior without argument like pwd)
  • 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 the clothes 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!

MartinDelille avatar Jan 10 '20 16:01 MartinDelille

This enhancement has not yet been implemented?

Theodikes avatar Aug 26 '22 18:08 Theodikes

Added support for subcommands.

p-ranav avatar Sep 21 '22 04:09 p-ranav