how to create a group named list/set, which is pthon build-in func #2666
-
my program name hostadmin, I want to use the follow command hostadmin list xx1 but how to create a group name list? import click
@click.group()
def cli():
pass
@cli.group()
def list():
pass
@list.command()
def xx1():
click.echo(f"xx1")
@list.command()
def xx2():
click.echo(f"xx2")
@cli.group()
def set():
pass
@set.command()
def xx1():
click.echo(f"xx1")
@set.command()
def xx2():
click.echo(f"xx2") I test the command it work ok, but Are there any hidden dangers? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
if xx2 func is bellow: @list.command()
def xx2():
bb = {1,2}
bb = list(bb)
click.secho(bb, fg='green') this may have error, how to avoid it? |
Beta Was this translation helpful? Give feedback.
-
The first argument to the @click.group("list")
def list_group():
pass In Click 8.2, functions with names that end in |
Beta Was this translation helpful? Give feedback.
The first argument to the
command
andgroup
decorators is a name. Otherwise, the decorator takes the name from the function. This way, you can avoid having function names that shadow built-in or other local names.In Click 8.2, functions with names that end in
_command
,_cmd
,_group
, and_grp
will use the name with those suffixes removed, so you won't have to specify the name manually.