Is it possible to do something like this with Python Click? I want to use different names for the same click.Group.
import click class CustomMultiGroup(click.Group): def group(self, *args, **kwargs): """Behaves the same as `click.Group.group()` except if passed a list of names, all after the first will be aliases for the first. """ def decorator(f): if isinstance(args[0], list): _args = [args[0][0]] + list(args[1:]) for alias in args[0][1:]: cmd = super(CustomMultiCommand, self).group( alias, *args[1:], **kwargs)(f) cmd.short_help = "Alias for '{}'".format(_args[0]) else: _args = args cmd = super(CustomMultiCommand, self).group( *_args, **kwargs)(f) return cmd return decorator @click.group(cls=CustomMultiGroup) def mycli(): pass @cli.group(['my-group', 'my-grp']) def my_group(): pass @my_group.command() def my_command(): pass I want my command lines to be something like:
mycli my-group my-command and
mycli my-grp my-command but reference the same function.
This post is a reference to Python Click multiple command names
@click.group()it would need to be@my_outer_group.group(), wheremy_outer_groupwas a previously declared group. Can you confirm this is the case?