Refactored the scripting interface greatly.

This commit is contained in:
Armin Ronacher 2014-08-25 16:50:22 +02:00
parent 66ef55ce0a
commit 932f7d7cbb
4 changed files with 65 additions and 36 deletions

View file

@ -762,9 +762,14 @@ Command Line Interface
.. autoclass:: FlaskGroup
:members:
.. autoclass:: AppGroup
:members:
.. autoclass:: ScriptInfo
:members:
.. autofunction:: with_appcontext
.. autofunction:: pass_script_info
.. autofunction:: without_appcontext
@ -774,8 +779,7 @@ Command Line Interface
A special decorator that informs a click callback to be passed the
script info object as first argument. This is normally not useful
unless you implement very special commands like the run command which
does not want the application to be loaded yet. This can be combined
with the :func:`without_appcontext` decorator.
does not want the application to be loaded yet.
.. autodata:: run_command

View file

@ -100,6 +100,24 @@ The command will then show up on the command line::
$ flask -a hello.py initdb
Init the db
Application Context
-------------------
Most commands operate on the application so it makes a lot of sense if
they have the application context setup. Because of this, if you register
a callback on ``app.cli`` with the :meth:`~flask.cli.AppGroup.command` the
callback will automatically be wrapped through :func:`cli.with_appcontext`
which informs the cli system to ensure that an application context is set
up. This behavior is not available if a command is lated later with
:func:`~click.Group.add_command` or through other means.
It can also be disabled by passing ``with_appcontext=False`` to the
decorator::
@app.cli.command(with_appcontext=False)
def example():
pass
Factory Functions
-----------------