Skip to content

Commit da60039

Browse files
dunkmann00davidism
authored andcommitted
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.
1 parent 08c480b commit da60039

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Version 3.1.1
44
Unreleased
55

66
- Fix type hint for `cli_runner.invoke`. :issue:`5645`
7+
- ``flask --help`` loads the app and plugins first to make sure all commands
8+
are shown. :issue:5673`
79

810

911
Version 3.1.0

src/flask/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ def make_context(
684684
return super().make_context(info_name, args, parent=parent, **extra)
685685

686686
def parse_args(self, ctx: click.Context, args: list[str]) -> list[str]:
687-
if not args and self.no_args_is_help:
687+
if (not args and self.no_args_is_help) or (
688+
len(args) == 1 and args[0] in self.get_help_option_names(ctx)
689+
):
688690
# Attempt to load --env-file and --app early in case they
689691
# were given as env vars. Otherwise no_args_is_help will not
690692
# see commands from app.cli.

0 commit comments

Comments
 (0)