lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
384 stars 46 forks source link

Subparsers with names different than dataclass names #222

Closed bouthilx closed 1 year ago

bouthilx commented 1 year ago

Hello! Is there a way to specify the name of the subparser I would want rather than using the class' name? I want to have informative class names but that does not lend well as commandline argument names.

Maybe something like this would be a clean solution if there are no other solutions supported yet?

@dataclass
class SomeSubCommand:
    __name__ = 'cli-name'
bouthilx commented 1 year ago

I found the solution using subparsers here: https://github.com/lebrice/SimpleParsing/blob/master/examples/subparsers/optional_subparsers.py#L21.

lebrice commented 1 year ago

You might also want to look into subgroups, which are a bit more flexible than subparsers: https://github.com/lebrice/SimpleParsing/tree/master/examples/subgroups