MCPcopy
hub / github.com/pallets/flask / FlaskGroup

Class FlaskGroup

src/flask/cli.py:531–696  ·  view source on GitHub ↗

Special subclass of the :class:`AppGroup` group that supports loading more commands from the configured Flask app. Normally a developer does not have to interface with this class but there are some very advanced use cases for which it makes sense to create an instance of this. see :

Source from the content-addressed store, hash-verified

529
530
531class FlaskGroup(AppGroup):
532 """Special subclass of the :class:`AppGroup` group that supports
533 loading more commands from the configured Flask app. Normally a
534 developer does not have to interface with this class but there are
535 some very advanced use cases for which it makes sense to create an
536 instance of this. see :ref:`custom-scripts`.
537
538 :param add_default_commands: if this is True then the default run and
539 shell commands will be added.
540 :param add_version_option: adds the ``--version`` option.
541 :param create_app: an optional callback that is passed the script info and
542 returns the loaded app.
543 :param load_dotenv: Load the nearest :file:`.env` and :file:`.flaskenv`
544 files to set environment variables. Will also change the working
545 directory to the directory containing the first file found.
546 :param set_debug_flag: Set the app's debug flag.
547
548 .. versionchanged:: 3.1
549 ``-e path`` takes precedence over default ``.env`` and ``.flaskenv`` files.
550
551 .. versionchanged:: 2.2
552 Added the ``-A/--app``, ``--debug/--no-debug``, ``-e/--env-file`` options.
553
554 .. versionchanged:: 2.2
555 An app context is pushed when running ``app.cli`` commands, so
556 ``@with_appcontext`` is no longer required for those commands.
557
558 .. versionchanged:: 1.0
559 If installed, python-dotenv will be used to load environment variables
560 from :file:`.env` and :file:`.flaskenv` files.
561 """
562
563 def __init__(
564 self,
565 add_default_commands: bool = True,
566 create_app: t.Callable[..., Flask] | None = None,
567 add_version_option: bool = True,
568 load_dotenv: bool = True,
569 set_debug_flag: bool = True,
570 **extra: t.Any,
571 ) -> None:
572 params: list[click.Parameter] = list(extra.pop("params", None) or ())
573 # Processing is done with option callbacks instead of a group
574 # callback. This allows users to make a custom group callback
575 # without losing the behavior. --env-file must come first so
576 # that it is eagerly evaluated before --app.
577 params.extend((_env_file_option, _app_option, _debug_option))
578
579 if add_version_option:
580 params.append(version_option)
581
582 if "context_settings" not in extra:
583 extra["context_settings"] = {}
584
585 extra["context_settings"].setdefault("auto_envvar_prefix", "FLASK")
586
587 super().__init__(params=params, **extra)
588

Callers 9

test_flaskgroup_nestedFunction · 0.90
test_help_echo_exceptionFunction · 0.90
invokeMethod · 0.90
test_no_routesMethod · 0.90
test_subdomainMethod · 0.90
test_hostMethod · 0.90
cli.pyFile · 0.85

Calls

no outgoing calls

Tested by 8

test_flaskgroup_nestedFunction · 0.72
test_help_echo_exceptionFunction · 0.72
invokeMethod · 0.72
test_no_routesMethod · 0.72
test_subdomainMethod · 0.72
test_hostMethod · 0.72