From da600394865c06a4772c433c1a560453dcf4f868 Mon Sep 17 00:00:00 2001 From: George Waters Date: Wed, 29 Jan 2025 22:22:52 -0500 Subject: [PATCH] Handle help arg by itself the same as no args When the 'flask' command is used with only the '--help' parameter, this change will make sure to try and load the app before the help callback is run. This was previously only being done when the 'flask' command was used by itself. This meant when passing in '--help', any custom commands were not getting shown in the help message. With this change, custom commands will be included in the help message when running 'flask' on the command line by itself or with the '--help' parameter. --- CHANGES.rst | 2 ++ src/flask/cli.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 14c6a6ac..fd88e12d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,8 @@ Version 3.1.1 Unreleased - Fix type hint for `cli_runner.invoke`. :issue:`5645` +- ``flask --help`` loads the app and plugins first to make sure all commands + are shown. :issue:5673` Version 3.1.0 diff --git a/src/flask/cli.py b/src/flask/cli.py index dd03f3c5..ed11f256 100644 --- a/src/flask/cli.py +++ b/src/flask/cli.py @@ -684,7 +684,9 @@ class FlaskGroup(AppGroup): return super().make_context(info_name, args, parent=parent, **extra) def parse_args(self, ctx: click.Context, args: list[str]) -> list[str]: - if not args and self.no_args_is_help: + if (not args and self.no_args_is_help) or ( + len(args) == 1 and args[0] in self.get_help_option_names(ctx) + ): # Attempt to load --env-file and --app early in case they # were given as env vars. Otherwise no_args_is_help will not # see commands from app.cli.