re-add flag to skip unguarded app.run from CLI

This commit is contained in:
David Lord 2022-06-29 21:11:58 -07:00
parent ab36542260
commit 5544d09477
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
3 changed files with 9 additions and 7 deletions

View file

@ -715,6 +715,11 @@ class FlaskGroup(AppGroup):
parent: click.Context | None = None,
**extra: t.Any,
) -> click.Context:
# Set a flag to tell app.run to become a no-op. If app.run was
# not in a __name__ == __main__ guard, it would start the server
# when importing, blocking whatever command is being called.
os.environ["FLASK_RUN_FROM_CLI"] = "true"
# Attempt to load .env and .flask env files. The --env-file
# option can cause another file to be loaded.
if get_load_dotenv(self.load_dotenv):