Move auto_envvar_prefix section to context section docs.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Edward G · committed by Edward G · parent d79f0fb · Browse files · 2 files·+51 added−50 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+51 added−50 removed
- other:+51 added−50 removed
Provenance
- Commit
82313af- Tree
4e82e23- Author
Edward G <edward.g2013@gmail.com>- Committer
Edward G <edward.g2013@gmail.com>- Parent
d79f0fb
2 files changed+51 added−50 removed
modified:docs/commands-and-groups.rst+51 added
214 unmodified lines215 216 Context Object217 -------------------218 The :class:`Context` object is how commands and groups communicate.219+220+Auto Envvar Prefix221+--------------------222+Automatically built environment variables are supported for options only. To enable this feature, the ``auto_envvar_prefix`` parameter needs to be passed to the script that is invoked. Each command and parameter is then added as an uppercase underscore-separated variable. If you have a subcommand223+called ``run`` taking an option called ``reload`` and the prefix is ``WEB``, then the variable is ``WEB_RUN_RELOAD``.224+225+Example usage:226+227+.. click:example::228+229+ @click.command()230+ @click.option('--username')231+ def greet(username):232+ click.echo(f'Hello {username}!')233+234+ if __name__ == '__main__':235+ greet(auto_envvar_prefix='GREETER')236+237+And from the command line:238+239+.. click:run::240+241+ invoke(greet, env={'GREETER_USERNAME': 'john'},242+ auto_envvar_prefix='GREETER')243+244+When using ``auto_envvar_prefix`` with command groups, the command name245+needs to be included in the environment variable, between the prefix and246+the parameter name, *i.e.* ``PREFIX_COMMAND_VARIABLE``. If you have a247+subcommand called ``run-server`` taking an option called ``host`` and248+the prefix is ``WEB``, then the variable is ``WEB_RUN_SERVER_HOST``.249+250+.. click:example::251+252+ @click.group()253+ @click.option('--debug/--no-debug')254+ def cli(debug):255+ click.echo(f"Debug mode is {'on' if debug else 'off'}")256+257+ @cli.command()258+ @click.option('--username')259+ def greet(username):260+ click.echo(f"Hello {username}!")261+262+ if __name__ == '__main__':263+ cli(auto_envvar_prefix='GREETER')264+265+.. click:run::266+267+ invoke(cli, args=['greet',],268+ env={'GREETER_GREET_USERNAME': 'John', 'GREETER_DEBUG': 'false'},269+ auto_envvar_prefix='GREETER')modified:docs/options.rst-50 removed
328 unmodified lines329 .. click:run::330 331 invoke(greet, env={'ALT_USERNAME': 'Bill', 'USERNAME': 'john'})332 333-Auto Envvar Prefix334---------------------335-Automatically built environment variables are supported for options only. To enable this feature, the ``auto_envvar_prefix`` parameter needs to be passed to the script that is invoked. Each command and parameter is then added as an uppercase underscore-separated variable. If you have a subcommand336-called ``run`` taking an option called ``reload`` and the prefix is ``WEB``, then the variable is ``WEB_RUN_RELOAD``.333 338-Example usage:339-340-.. click:example::341-342- @click.command()343- @click.option('--username')344- def greet(username):345- click.echo(f'Hello {username}!')346-347- if __name__ == '__main__':348- greet(auto_envvar_prefix='GREETER')349-350-And from the command line:351-352-.. click:run::353-354- invoke(greet, env={'GREETER_USERNAME': 'john'},355- auto_envvar_prefix='GREETER')356-357-When using ``auto_envvar_prefix`` with command groups, the command name358-needs to be included in the environment variable, between the prefix and359-the parameter name, *i.e.* ``PREFIX_COMMAND_VARIABLE``. If you have a360-subcommand called ``run-server`` taking an option called ``host`` and361-the prefix is ``WEB``, then the variable is ``WEB_RUN_SERVER_HOST``.362-363-.. click:example::364-365- @click.group()366- @click.option('--debug/--no-debug')367- def cli(debug):368- click.echo(f"Debug mode is {'on' if debug else 'off'}")369-370- @cli.command()371- @click.option('--username')372- def greet(username):373- click.echo(f"Hello {username}!")374-375- if __name__ == '__main__':376- cli(auto_envvar_prefix='GREETER')377-378-.. click:run::379-380- invoke(cli, args=['greet',],381- env={'GREETER_GREET_USERNAME': 'John', 'GREETER_DEBUG': 'false'},382- auto_envvar_prefix='GREETER')383-334 Multiple Options from Environment Values335 -----------------------------------------336 337 As options can accept multiple values, pulling in such values from74 unmodified lines