Merge branch 'cli-rewrite' into docs-javascript
This commit is contained in:
commit
f519d2185f
2 changed files with 53 additions and 4 deletions
|
|
@ -338,7 +338,7 @@ class ScriptInfo:
|
|||
|
||||
def __init__(self, app_import_path=None, create_app=None, set_debug_flag=True):
|
||||
#: Optionally the import path for the Flask application.
|
||||
self.app_import_path = app_import_path or os.environ.get("FLASK_APP")
|
||||
self.app_import_path = app_import_path
|
||||
#: Optionally a function that is passed the script info to create
|
||||
#: the instance of the application.
|
||||
self.create_app = create_app
|
||||
|
|
@ -403,8 +403,11 @@ def with_appcontext(f):
|
|||
|
||||
@click.pass_context
|
||||
def decorator(__ctx, *args, **kwargs):
|
||||
with __ctx.ensure_object(ScriptInfo).load_app().app_context():
|
||||
return __ctx.invoke(f, *args, **kwargs)
|
||||
if not current_app:
|
||||
app = __ctx.ensure_object(ScriptInfo).load_app()
|
||||
__ctx.with_resource(app.app_context())
|
||||
|
||||
return __ctx.invoke(f, *args, **kwargs)
|
||||
|
||||
return update_wrapper(decorator, f)
|
||||
|
||||
|
|
@ -477,7 +480,36 @@ class FlaskGroup(AppGroup):
|
|||
if add_version_option:
|
||||
params.append(version_option)
|
||||
|
||||
AppGroup.__init__(self, params=params, **extra)
|
||||
def set_app(ctx, param, value):
|
||||
info: ScriptInfo = ctx.ensure_object(ScriptInfo)
|
||||
info.app_import_path = value
|
||||
|
||||
def set_env(ctx, param, value):
|
||||
info: ScriptInfo = ctx.ensure_object(ScriptInfo)
|
||||
info.app_env = value
|
||||
|
||||
params.append(
|
||||
click.Option(
|
||||
["--app"],
|
||||
metavar="IMPORT",
|
||||
help="Import string for a Flask app object or factory function.",
|
||||
callback=set_app,
|
||||
is_eager=True,
|
||||
)
|
||||
)
|
||||
params.append(
|
||||
click.Option(
|
||||
["--env"],
|
||||
metavar="ENV",
|
||||
help="Runtime environment name.",
|
||||
default="production",
|
||||
show_default=True,
|
||||
callback=set_env,
|
||||
is_eager=True,
|
||||
)
|
||||
)
|
||||
super().__init__(params=params, **extra)
|
||||
|
||||
self.create_app = create_app
|
||||
self.load_dotenv = load_dotenv
|
||||
self.set_debug_flag = set_debug_flag
|
||||
|
|
|
|||
17
src/flask/cli2.py
Normal file
17
src/flask/cli2.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import os
|
||||
|
||||
import click
|
||||
|
||||
|
||||
@click.group("flask")
|
||||
@click.option("--app", "app")
|
||||
@click.option("--env")
|
||||
@click.pass_context
|
||||
def flask_group(ctx: click.Context, app: str, env: str) -> None:
|
||||
os.environ["FLASK_RUN_FROM_CLI"] = "true"
|
||||
# info = ctx.ensure_object(ScriptInfo)
|
||||
|
||||
|
||||
@flask_group.command("run")
|
||||
def run_command():
|
||||
click.echo("run")
|
||||
Loading…
Add table
Add a link
Reference in a new issue