Skip to content
Myr

Documenting how `auto_envvar_prefix` works with command groups

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Doug Harris · committed by Doug Harris · parent 39e46e0 · Browse files · 1 file+27 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+27 added−0 removed

  • other:+27 added−0 removed

1 file+27 added−0 removed

modified:docs/options.rst+27 added
555 unmodified lines
556557 invoke(greet, env={'GREETER_USERNAME': 'john'},558 auto_envvar_prefix='GREETER')559560When using ``auto_envvar_prefix`` with command groups, the command name needs561to be included in the environment variable, between the prefix and the parameter name, *i.e.* *PREFIX_COMMAND_VARIABLE*.562563Example:564565.. click:example::566567 @click.group()568 @click.option('--debug/--no-debug')569 def cli(debug):570 click.echo('Debug mode is %s' % ('on' if debug else 'off'))571572 @cli.command()573 @click.option('--username')574 def greet(username):575 click.echo('Hello %s!' % username)576577 if __name__ == '__main__':578 cli(auto_envvar_prefix='GREETER')579580.. click:run::581582 invoke(cli, args=['greet',],583 env={'GREETER_GREET_USERNAME': 'John', 'GREETER_DEBUG': 'false'},584 auto_envvar_prefix='GREETER')585586587The second option is to manually pull values in from specific environment588variables by defining the name of the environment variable on the option.589590Example usage:
175 unmodified lines