python全栈

python 命令行工具包click

1. 官方文档

https://click.palletsprojects.com/en/8.1.x/

2. 示例

import click

@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name',
              help='The person to greet.')
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for x in range(count):
        click.echo(f"Hello {name}!")

if __name__ == '__main__':
    hello()
lintianlaideMacBook-Air:~ lintianlai$ python3 cli.py --help
Usage: cli.py [OPTIONS]

  Simple program that greets NAME for a total of COUNT times.

Options:
  --count INTEGER  Number of greetings.
  --name TEXT      The person to greet.
  --help           Show this message and exit.
lintianlaideMacBook-Air:~ lintianlai$ python3 cli.py --name LinTianlai --count 3
Hello LinTianlai!
Hello LinTianlai!
Hello LinTianlai!

留言

您的电子邮箱地址不会被公开。 必填项已用*标注

闽ICP备20008591号-1