Flask-CLI¶
Flask-CLI is a backport of Flask 1.0 new click integration to v0.10.
Do not install this package if you use Flask 1.0+.
Full documentation of Flask’s new click command line integration can be found at: http://flask.pocoo.org/docs/dev/cli/.
Usage¶
Initialize the extension like this:
import click
from flask import Flask
from flask_cli import FlaskCLI
app = Flask('myapp')
FlaskCLI(app)
@app.cli.command()
def mycmd():
click.echo("Test")
CLI Plugins¶
Flask extensions can always patch the Flask.cli instance with more commands if they want. However there is a second way to add CLI plugins to Flask which is through setuptools. If you make a Python package that should export a Flask command line plugin you can ship a setup.py file that declares an entrypoint that points to a click command:
Example setup.py:
from setuptools import setup
setup(
name='flask-my-extension',
...
entry_points='''
[flask.commands]
my-command=mypackage.commands:cli
''',
)
Inside mypackage/comamnds.py you can then export a Click object:
import click
@click.command()
def cli():
"""This is an example command."""
Once that package is installed in the same virtualenv as Flask itself you
can run flask my-command
to invoke your command. This is useful to
provide extra functionality that Flask itself cannot ship.
Import from this library instead of flask.cli
, e.g.:
from flask_cli import FlaskGroup
Changes¶
Version 0.4.0 (released 2016-06-28)
- Adds a –version switch to Flask CLI.
- Updates help to > set FLASK_APP=hello.py.
- Adds plugin support to the CLI.
- Updates docs to the new CLI patterns.
- Removes Python 2.6 and adds Python 3.5 to Tox configuration to match Travis config.
- Implements simplified CLI interface.
Version 0.3.0 (released 2016-05-17)
- Werkzeug should not block propagated exceptions from Flask.
- Fixes issue with the parameter passed to the CLI’s AppGroup.
- Adds shell context processor example.
- Fixes missing import in Python example in README.
- Fixes broken tests.
Version 0.2.1 (released 2015-08-03)
- Adds support for specifying shell context processors.
- Fixes bug with shell command due to missing support for shell context processors.
Version 0.2.0 (released 2015-07-31)
- Adds FlaskCLI extension to support app.cli.
- Changes default imports from flask_cli.cli to flask_cli and relies on Flask’s classes when v1.0 is installed.
Version 0.1.0 (released 2015-07-31)
- Initial public release
Contributing¶
Bug reports, feature requests, and other contributions are welcome. If you find a demonstrable problem that is caused by the code of this library, please:
- Search for already reported problems.
- Check if the issue has been fixed or is still reproducible on the latest master branch.
- Create an issue with a test case.
If you create a feature branch, you can run the tests to ensure everything is operating correctly:
$ ./run-tests.sh
You can also test your feature branch using Docker:
$ docker-compose build
$ docker-compose run --rm web /code/run-tests.sh
License¶
Flask-CLI is free software; you can redistribute it and/or modify it under the terms of the Revised BSD License quoted below.
Copyright (C) 2015 CERN.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an Intergovernmental Organization or submit itself to any jurisdiction.
The following files are under different license/copyright:
flask_cli/cli.py
flask_cli/_compat.py
flask_cli/app.py
Copyright (c) 2015 by Armin Ronacher and contributors.
Some rights reserved.
Redistribution and use in source and binary forms of the software as well as documentation, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE AND DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors¶
Contact us at info@invenio-software.org
- Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
This package includes code from Flask, which has not been developed by the authors. Please see LICENSE for further details.