使用 Python 创建分层命令 单击

Creating hierarchical commands using Python Click

假设我想创建一个如下所示的 CLI

cliName user create
cliName user update

我该怎么做?

我试过这样做 -

@click.group()
def user():
   print("USER")
   pass

@user.command()
def create():
    click.echo("create user called")

当我运行cliName user create时,打印语句不会运行。没有 运行s.

#!/usr/bin/env python

import click


@click.group()
def cli(**kwargs):
    print(1)


@cli.group()
@click.option("--something")
@click.option("--else")
def what(**kwargs):
    print(2)


@what.command()
@click.option("--chaa")
def ever(**kwargs):
    print(3)


if __name__ == '__main__':
    cli()


# ./cli.py what ever
# 1
# 2
# 3