diff options
author | Doug Harris <dharris@gmail.com> | 2018-05-15 15:13:33 -0400 |
---|---|---|
committer | Doug Harris <dharris@gmail.com> | 2018-05-15 15:14:08 -0400 |
commit | 622296e016c155926e78252800617f1c7a82eb89 (patch) | |
tree | 1c8a7cfa66ad088df064f01ee8a9bd5061afd4ce /docs/options.rst | |
parent | 39e46e09cb0d61394da6ec26c05541ac9a50ed00 (diff) | |
download | click-622296e016c155926e78252800617f1c7a82eb89.tar.gz |
Documenting how `auto_envvar_prefix` works with command groups
Diffstat (limited to 'docs/options.rst')
-rw-r--r-- | docs/options.rst | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/docs/options.rst b/docs/options.rst index 947550a..125ee44 100644 --- a/docs/options.rst +++ b/docs/options.rst @@ -557,6 +557,33 @@ And from the command line: invoke(greet, env={'GREETER_USERNAME': 'john'}, auto_envvar_prefix='GREETER') +When using ``auto_envvar_prefix`` with command groups, the command name needs +to be included in the environment variable, between the prefix and the parameter name, *i.e.* *PREFIX_COMMAND_VARIABLE*. + +Example: + +.. click:example:: + + @click.group() + @click.option('--debug/--no-debug') + def cli(debug): + click.echo('Debug mode is %s' % ('on' if debug else 'off')) + + @cli.command() + @click.option('--username') + def greet(username): + click.echo('Hello %s!' % username) + + if __name__ == '__main__': + cli(auto_envvar_prefix='GREETER') + +.. click:run:: + + invoke(cli, args=['greet',], + env={'GREETER_GREET_USERNAME': 'John', 'GREETER_DEBUG': 'false'}, + auto_envvar_prefix='GREETER') + + The second option is to manually pull values in from specific environment variables by defining the name of the environment variable on the option. |