|
|
|
@ -289,6 +289,53 @@ group. This is useful if you want to organize multiple related commands. ::
|
|
|
|
|
|
|
|
|
|
flask user create demo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
If your application uses blueprints, you can optionally register cli |
|
|
|
|
commands directly onto them. |
|
|
|
|
When your blueprint is registered onto your application the associated |
|
|
|
|
commands will be available to the ``flask`` command. |
|
|
|
|
By default those commands will be nested in a group matching the |
|
|
|
|
name of the blueprint. :: |
|
|
|
|
|
|
|
|
|
from flask import Blueprint |
|
|
|
|
bp = Blueprint('students', __name__) |
|
|
|
|
|
|
|
|
|
@bp.cli.command('create') |
|
|
|
|
@click.argument('name') |
|
|
|
|
def create(name): |
|
|
|
|
... |
|
|
|
|
|
|
|
|
|
app.register_blueprint(bp) |
|
|
|
|
|
|
|
|
|
:: |
|
|
|
|
|
|
|
|
|
flask students create alice |
|
|
|
|
|
|
|
|
|
You can alter the cli group name by specifying the ``cli_group`` keyword |
|
|
|
|
argument when creating the :class:`Blueprint` object or later during |
|
|
|
|
:meth:`app.register_blueprint(bp, cli_group='...') <Flask.register_blueprint>` |
|
|
|
|
process, the following are equivilant:: |
|
|
|
|
|
|
|
|
|
bp = Blueprint('students', __name__, cli_group='other') |
|
|
|
|
... |
|
|
|
|
app.register_blueprint(bp, cli_group='other') |
|
|
|
|
|
|
|
|
|
:: |
|
|
|
|
|
|
|
|
|
flask other create alice |
|
|
|
|
|
|
|
|
|
Specifying ``cli_group=None`` will remove the nesting and merge the commands |
|
|
|
|
directly to the application's level:: |
|
|
|
|
|
|
|
|
|
bp = Blueprint('students', __name__, cli_group=None) |
|
|
|
|
... |
|
|
|
|
app.register_blueprint(bp, cli_group=None) |
|
|
|
|
|
|
|
|
|
:: |
|
|
|
|
|
|
|
|
|
flask create alice |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
See :ref:`testing-cli` for an overview of how to test your custom |
|
|
|
|
commands. |
|
|
|
|
|
|
|
|
|