Added missing documentation page
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 67e4d3e · Browse files · 1 file·+101 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+101 added−0 removed
- other:+101 added−0 removed
Provenance
- Commit
9841420- Tree
24c23da- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
67e4d3e
1 file changed+101 added−0 removed
added:docs/cli.rst+101 added
1+.. _cli:2+3+Command Line Interface4+======================5+6+.. versionadded:: 1.07+8+.. currentmodule:: flask9+10+One of the nice new features in Flask 1.0 is the built-in integration of11+the `click <http://click.pocoo.org/>`_ command line interface. This12+enables a wide range of new features for the Flask ecosystem and your own13+applications.14+15+Basic Usage16+-----------17+18+After installation of Flask you will now find a ``flask`` script installed19+into your virtualenv. If you don't want to install Flask or you have a20+special use-case you can also use ``python -mflask`` to accomplish exactly21+the same.22+23+The way this script works is by providing access to all the commands on24+your Flask application's :attr:`Flask.cli` instance as well as some25+built-in commands that are always there. Flask extensions can also26+register more commands there if they so desire.27+28+For the ``flask`` script to work, an application needs to be discovered.29+The two most common ways are either an environment variable30+(``FLASK_APP``) or the ``--app`` / ``-a`` parameter. It should be the31+import path for your application or the path to a Python file. In the32+latter case Flask will attempt to setup the Python path for you33+automatically and discover the module name but that might not always work.34+35+In that imported file the name of the app needs to be called ``app`` or36+optionally be specified after a colon.37+38+Given a ``hello.py`` file with the application in it named ``app`` this is39+how it can be run.40+41+Environment variables (On Windows use ``set`` instead of ``export``)::42+43+ export FLASK_APP=hello44+ flask run45+46+Parameters::47+48+ flask --app=hello run49+50+File names::51+52+ flask --app=hello.py run53+54+Virtualenv Integration55+----------------------56+57+If you are constantly working with a virtualenv you can also put the58+``export FLASK_APP`` into your ``activate`` script by adding it to the59+bottom of the file. That way every time you activate your virtualenv you60+automatically also activate the correct application name.61+62+Debug Flag63+----------64+65+The ``flask`` script can be run with ``--debug`` or ``--no-debug`` to66+automatically flip the debug flag of the application. This can also be67+configured by setting ``FLASK_DEBUG`` to ``1`` or ``0``.68+69+Running a Shell70+---------------71+72+To run an interactive Python shell you can use the ``shell`` command::73+74+ flask --app=hello shell75+76+This will start up an interactive Python shell, setup the correct77+application context and setup the local variables in the shell. This is78+done by invoking the :meth:`Flask.make_shell_context` method of the79+application. By default you have access to your ``app`` and :data:`g`.80+81+Custom Commands82+---------------83+84+If you want to add more commands to the shell script you can do this85+easily. Flask uses `click`_ for the command interface which makes86+creating custom commands very easy. For instance if you want a shell87+command to initialize the database you can do this::88+89+ from flask import Flask90+91+ app = Flask(__name__)92+93+ @app.cli.command()94+ def initdb():95+ """Initialize the database."""96+ print 'Init the db'97+98+The command will then show up on the command line::99+100+ $ flask -a hello.py initdb101+ Init the db