How to get all available Command Options to set environment variables?

核能气质少年 提交于 2020-07-09 05:13:45

问题


The flask manual about Setting Command Options only talks about the command FLASK_RUN_PORT to set environment variables that can be loaded by Click.

How can i find the other options and use them with the pattern FLASK_COMMAND_OPTION ?

I want to set it to my vscode launch.json.


回答1:


You can access all available commands by executing in a shell :

flask --help
[...]
Commands:
      db     Perform database migrations.
      run    Runs a development server.
      shell  Runs a shell in the app context.

Then if you want to list all available options for a given command like run:

flask run --help 
Options:
      -h, --host TEXT                 The interface to bind to.
      -p, --port INTEGER              The port to bind to.
      --reload / --no-reload          Enable or disable the reloader.  By default
                                      the reloader is active if debug is enabled.
      --debugger / --no-debugger      Enable or disable the debugger.  By default
                                      the debugger is active if debug is enabled.
      --eager-loading / --lazy-loader
                                      Enable or disable eager loading.  By default
                                      eager loading is enabled if the reloader is
                                      disabled.
      --with-threads / --without-threads
                                      Enable or disable multithreading.
      --help                          Show this message and exit.

So you can use them with the pattern like in the doc examples, you just have to concatenate the name and the options with underscores, in ALLCAPS:

export FLASK_RUN_PORT=8000
export FLASK_RUN_HOST=0.0.0.0

You can also define boolean options :

export FLASK_RUN_RELOAD=True   
export FLASK_RUN_RELOAD=False

NOTE : flask --help will list default commands, but if you define your app before executing this help (export FLASK_APP=my_app.py), you will also get all custom commands.

Commands:
      db      Perform database migrations.
      deploy
      run     Runs a development server.
      shell   Runs a shell in the app context.
      test    perform tests


来源:https://stackoverflow.com/questions/50389273/how-to-get-all-available-command-options-to-set-environment-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!