add --app, --env, --debug, and --env-file CLI options#4646
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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_DEBUGcan be set with options to theflaskCLI instead of requiring that they be set with env vars. They can still be set with env vars.-e, --env-filespecifies an additional dotenv file to load, in addition to.envand.flaskenv.FLASK_SKIP_DOTENVdoes not skip this option, only the two default files. Did not add an option forFLASK_SKIP_DOTENVsince it's only useful when being called from another CLI that already manages env vars and can set it already.-A, --app-E, --envworks by setting theFLASK_ENVenv 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-debugonly setsapp.debugif it's actually provided on the command line, and works like--envby setting theFLASK_DEBUGenv var. It is still skipped for now ifScriptInfo.set_debug_flagisFalsebecause 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
--helpandno_args_is_helpwon't see it in time to list the commands. And--env-fileneeds to be evaluated the earliest because it can setFLASK_APP. Both these options areis_eager=True, and also get processed beforeparse_argsruns 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