存放日常开发所撰写的Markdown文件。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
544 B

3 years ago
# CLI 工具
---
Flask 提供CLI 库来运行Command 的内容。
示例代码:
```py
import click
@app.cli.command("hello")
@click.option("--name", default="World")
def hello_command(name):
click.echo(f"Hello, {name}!")
def test_hello_command(runner):
result = runner.invoke(args="hello")
assert "World" in result.output
result = runner.invoke(args=["hello", "--name", "Flask"])
assert "Flask" in result.output
```
其中,@click.option 使用来申明方法的参数格式。而def 所编写的则是方法。