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.
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.
Most helpful comment
Having both
blueprint.app_cliandblueprint.cliseems 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:
Command would need to be run as
myapp blue doblueprintstuff.Called as:
myapp doblueprintstuff.