Method: flask.cli.with_appcontext
Calls: 16, Exceptions: 0, Paths: 1Back
Path 1: 16 calls (1.0)
test_flaskgroup_debug.
test_flaskgroup_debug.
1def with_appcontext(f):
2 """Wraps a callback so that it's guaranteed to be executed with the
3 script's application context.
4
5 Custom commands (and their options) registered under ``app.cli`` or
6 ``blueprint.cli`` will always have an app context available, this
7 decorator is not required in that case.
8
9 .. versionchanged:: 2.2
10 The app context is active for subcommands as well as the
11 decorated callback. The app context is always available to
12 ``app.cli`` command and parameter callbacks.
13 """
14
15 @click.pass_context
16 def decorator(__ctx, *args, **kwargs):
17 if not current_app:
18 app = __ctx.ensure_object(ScriptInfo).load_app()
19 __ctx.with_resource(app.app_context())
20
21 return __ctx.invoke(f, *args, **kwargs)
22
23 return update_wrapper(decorator, f)