From 2ecc70bfd6d7bae65eee27ed1b1ac93fe95e4b48 Mon Sep 17 00:00:00 2001 From: Anthony Plunkett Date: Tue, 15 May 2018 12:34:23 -0400 Subject: [PATCH] Documentation for blueprint cli registration --- docs/cli.rst | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/docs/cli.rst b/docs/cli.rst index 7ce63fd2..f1a83f66 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -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='...') ` +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.