I have a tool
that manipulates two resources: r1
and r2
. Each of which has its own click group, with get
command inside:
import click
@click.group
def cli():
pass
@cli.group
def r1():
pass
@r1.command("get")
def r1_get():
click.echo("r1.get")
@cli.group
def r2():
pass
@r2.command("get")
def r2_get():
click.echo("r2.get")
if __name__ == "__main__":
from click.utils import get_os_args
cli(get_os_args())
I can invoke commands:
$ tool r1 get
r1.get
$ tool r2 get
r2.get
I'd used recipe from https://stackoverflow.com/a/47985653/38592 to create aliases:
aliases = dict(
r1get='r1 get'.split(),
r2get='r2 get'.split(),
)
@click.group(cls=ExpandAliasesGroup, aliases=aliases)
def cli():
pass
This fills root group of my tool
with aliases:
$ tool r1get
r1.get
$ tool r2get
r2.get
I want to enable following:
$ tool get r1
r1.get
$ tool get r2
r2.get
I'd tried something like this:
aliases = dict(
r1='r1 get'.split(),
r2='r2 get'.split(),
)
@cli.group(cls=ExpandAliasesGroup, aliases=aliases)
def get():
pass
But this does not work, since r1
and r2
are outside of scope of the get
group.
$ tool get r1
Error: No such command 'r1'.
$ tool get r2
Error: No such command 'r2'.
What should be proper way to group such aliases into its own get
group?