Skip to content
Myr

FlaskGroup can be nested

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent 4f03a76 · Browse files · 3 files+36 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+36 added−10 removed

  • tests:+13 added−0 removed
  • other:+23 added−10 removed

3 files+36 added−10 removed

modified:src/flask/cli.py+20 added-10 removed
3 unmodified lines
4import platform5import re6import sys7import traceback8import typing as t9from functools import update_wrapper10from operator import attrgetter11from threading import Lock12from threading import Thread
465 unmodified lines
478479 if add_version_option:480 params.append(version_option)481481 AppGroup.__init__(self, params=params, **extra)482 if "context_settings" not in extra:483 extra["context_settings"] = {}484485 extra["context_settings"].setdefault("auto_envvar_prefix", "FLASK")486487 super().__init__(params=params, **extra)488489 self.create_app = create_app490 self.load_dotenv = load_dotenv491 self.set_debug_flag = set_debug_flag492
59 unmodified lines
552 click.secho(f"{traceback.format_exc()}\n", err=True, fg="red")553554 return sorted(rv)555549 def main(self, *args, **kwargs):556 def make_context(557 self,558 info_name: t.Optional[str],559 args: t.List[str],560 parent: t.Optional[click.Context] = None,561 **extra: t.Any,562 ) -> click.Context:563 if get_load_dotenv(self.load_dotenv):564 load_dotenv()565553 obj = kwargs.get("obj")554555 if obj is None:556 obj = ScriptInfo(566 if "obj" not in extra and "obj" not in self.context_settings:567 extra["obj"] = ScriptInfo(568 create_app=self.create_app, set_debug_flag=self.set_debug_flag569 )570560 kwargs["obj"] = obj561 kwargs.setdefault("auto_envvar_prefix", "FLASK")562 return super().main(*args, **kwargs)571 return super().make_context(info_name, args, parent=parent, **extra)572573574def _path_is_ancestor(path, other):575 """Take ``other`` and remove the length of ``path`` from it. Then join it
390 unmodified lines
966 click.echo(row.format(rule.endpoint, methods, rule.rule).rstrip())967968969cli = FlaskGroup(970 name="flask",971 help="""\972A general utility script for Flask applications.973974Provides commands from Flask, extensions, and the application. Loads the
7 unmodified lines
982 {prefix}flask run983""".format(984 cmd="export" if os.name == "posix" else "set",985 prefix="$ " if os.name == "posix" else "> ",976 )986 ),987)988989990def main() -> None:
5 unmodified lines
modified:tests/test_cli.py+13 added
386 unmodified lines
387 assert result.exit_code == 0388 assert result.output == f"{not set_debug_flag}\n"389390391def test_flaskgroup_nested(app, runner):392 cli = click.Group("cli")393 flask_group = FlaskGroup(name="flask", create_app=lambda: app)394 cli.add_command(flask_group)395396 @flask_group.command()397 def show():398 click.echo(current_app.name)399400 result = runner.invoke(cli, ["flask", "show"])401 assert result.output == "flask_test\n"402403404def test_no_command_echo_loading_error():405 from flask.cli import cli406407 runner = CliRunner(mix_stderr=False)
276 unmodified lines
modified:CHANGES.rst+3 added
23 unmodified lines
24 the application instead. :issue:`4605`25- Added the ``View.init_every_request`` class attribute. If a view26 subclass sets this to ``False``, the view will not create a new27 instance on every request. :issue:`2520`.28- A ``flask.cli.FlaskGroup`` Click group can be nested as a29 sub-command in a custom CLI. :issue:`3263`303132Version 2.1.333-------------3435Unreleased
1289 unmodified lines