I'm using the FlaskGroup command group to extend the Flask cli like so:
@click.group(cls=FlaskGroup, create_app=create_cli_app, context_settings=CONTEXT_SETTINGS)
@click.option(
'--debug',
'-d',
is_flag=True,
default=False,
help='Force debug mode to be on. Dev config already enables this, so only use when needed.')
@click.option(
'--config',
'-c',
default=None,
type=click.Choice(['dev', 'prod']),
help='The configuration profile to use when running this app.')
@click.pass_context
def cli(ctx, debug, config):
if debug:
os.environ['FLASK_DEBUG'] = '1'
if config is not None:
os.environ['APP_SETTINGS'] = {
'dev': 'config.DevelopmentConfig',
'prod': 'config.ProductionConfig',
}[config]
However when using Flask-SocketIO with eventlet this doesn't seem to show any of the options defined in Flask-SocketIO's cli what is the recommended way to extend your cli when using FlaskGroup?
I don't have a huge amount of experience with click, so maybe there's a straightforward way that I'm missing.
Not sure what the problem might be. Using the example custom script from the docs (http://flask.pocoo.org/docs/0.12/cli/#custom-scripts) the help for flask run is the one from Flask-SocketIO, so things seem to be working as designed.
Can you provide an example of how it would with FlaskGroup ?
In my manage.py, I have
app = create_app()
cli = FlaskGroup(create_app=create_app)
...
@cli.command()
def create_admin():
# function that use app.config here
pass
if __name__ == '__main__':
cli()
and I am not sure how to add socketio.run(app) in the mix.
Thanks
@maclandrol if you use the Flask CLI you don't need the socketio.run() call. You can start the server with flask run, as you normally do for Flask apps. Flask-SocketIO modifies the implementation of flask run to invoke socketio.run(app) for you.
It worked, thanks.
Most helpful comment
@maclandrol if you use the Flask CLI you don't need the
socketio.run()call. You can start the server withflask run, as you normally do for Flask apps. Flask-SocketIO modifies the implementation offlask runto invokesocketio.run(app)for you.