Flask: Support for @blueprint.cli.command

Created on 20 Feb 2015  路  3Comments  路  Source: pallets/flask

It would be great to have access to the functionality of app.cli.command via blueprints - i.e. something like:

blueprint = Blueprint('myblueprint', __name__,)

@blueprint.cli.command()
def doblueprintstuff():
    """Initialize the database."""
    #....

It would help a lot when building modular applications.

blueprints cli

Most helpful comment

Having both blueprint.app_cli and blueprint.cli seems not ideal to me. Also, you should have a way to specific the subcommand group a command falls under. Default that to the blueprint name, but allow an override.

Other options:

blueprint = Blueprint('myblueprint', __name__, cli_group_name='blue')

@blueprint.cli.command()
def doblueprintstuff():
    """Initialize the database."""
    #....

Command would need to be run as myapp blue doblueprintstuff.

blueprint = Blueprint('myblueprint', __name__, cli_group_name='blue')

@blueprint.cli.command(on_app=True)
def doblueprintstuff():
    """Initialize the database."""
    #....

Called as: myapp doblueprintstuff.

All 3 comments

Sounds like a useful feature. The question is.. would the command become a direct subcommand of flask such as flask doblueprintstuff or be somehow separated, e.g. flask myblueprint doblueprintstuff. I could imagine arguments for both cases depending on the applications.

Maybe blueprint.cli.command and blueprint.app_cli.command similar to how blueprints can modify some things (e.g. error handlers) either globally for the whole app or just for the blueprint.

Maybe blueprint.cli.command and blueprint.app_cli.command similar to how blueprints can modify some things (e.g. error handlers) either globally for the whole app or just for the blueprint.

Yep, I can see valid uses cases for both as well, so I think blueprint.cli.command and blueprint.app_cli.command is a nice way to not force a particular scheme upon developers.

Having both blueprint.app_cli and blueprint.cli seems not ideal to me. Also, you should have a way to specific the subcommand group a command falls under. Default that to the blueprint name, but allow an override.

Other options:

blueprint = Blueprint('myblueprint', __name__, cli_group_name='blue')

@blueprint.cli.command()
def doblueprintstuff():
    """Initialize the database."""
    #....

Command would need to be run as myapp blue doblueprintstuff.

blueprint = Blueprint('myblueprint', __name__, cli_group_name='blue')

@blueprint.cli.command(on_app=True)
def doblueprintstuff():
    """Initialize the database."""
    #....

Called as: myapp doblueprintstuff.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jab picture jab  路  4Comments

ghostbod99 picture ghostbod99  路  4Comments

stillesjo picture stillesjo  路  4Comments

fb picture fb  路  5Comments

maangulo12 picture maangulo12  路  4Comments