Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

flask

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.

like image 640
Kamil Avatar asked Mar 06 '23 04:03

Kamil


1 Answers

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
like image 191
PRMoureu Avatar answered Mar 23 '23 04:03

PRMoureu