使用示例
配合 .flaskenv 环境变量设置使用
默认: FLASK_APP=app
app.py
import click from flask import Flask from flask.cli import AppGroup app = Flask(__name__) # 方式一 @app.cli.command("create-user") @click.argument("name") def create_user(name): print('create_user', name) # 方式二 user_cli = AppGroup('user') @user_cli.command('create') @click.argument('name') def create_user(name): print('create user', name) app.cli.add_command(user_cli)
使用测试
$ flask create-user admin create_user admin $ flask user create demo create user demo