add --app
, --env
, --debug
, and --env-file
CLI options
#4646
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
FLASK_APP
,FLASK_ENV
, andFLASK_DEBUG
can be set with options to theflask
CLI instead of requiring that they be set with env vars. They can still be set with env vars.-e, --env-file
specifies an additional dotenv file to load, in addition to.env
and.flaskenv
.FLASK_SKIP_DOTENV
does not skip this option, only the two default files. Did not add an option forFLASK_SKIP_DOTENV
since it's only useful when being called from another CLI that already manages env vars and can set it already.-A, --app
-E, --env
works by setting theFLASK_ENV
env var internally, as this is still the only way it can be available early enough duringFlask.__init__
and factory functions without making it an argument to__init__
.--debug/--no-debug
only setsapp.debug
if it's actually provided on the command line, and works like--env
by setting theFLASK_DEBUG
env var. It is still skipped for now ifScriptInfo.set_debug_flag
isFalse
because I couldn't think of a good way to do that.This did require some tricks to get custom commands to work. The app needs to be loaded as early as possible, otherwise
--help
andno_args_is_help
won't see it in time to list the commands. And--env-file
needs to be evaluated the earliest because it can setFLASK_APP
. Both these options areis_eager=True
, and also get processed beforeparse_args
runs in case they were only given as env vars.All docs are rewritten to use the CLI options instead of environment variables in most cases. Some areas still call out or show how to use environment variables.
fixes #2292
fixes #3108