Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --app, --env, --debug, and --env-file CLI options #4646

Merged
merged 2 commits into from
Jun 17, 2022
Merged

Conversation

davidism
Copy link
Member

FLASK_APP, FLASK_ENV, and FLASK_DEBUG can be set with options to the flask 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 for FLASK_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 the FLASK_ENV env var internally, as this is still the only way it can be available early enough during Flask.__init__ and factory functions without making it an argument to __init__.
  • --debug/--no-debug only sets app.debug if it's actually provided on the command line, and works like --env by setting the FLASK_DEBUG env var. It is still skipped for now if ScriptInfo.set_debug_flag is False 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 and no_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 set FLASK_APP. Both these options are is_eager=True, and also get processed before parse_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

@davidism davidism added the cli label Jun 17, 2022
@davidism davidism added this to the 2.2.0 milestone Jun 17, 2022
@davidism davidism merged commit ae54727 into main Jun 17, 2022
@davidism davidism deleted the cli-app-env branch June 17, 2022 16:30
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

config option for "flask run" (e.g. --dotenv/-e) Investigate adding app and debug args back into the CLI
1 participant