Skip to content
Myr

Added example for token normalization.

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

authored by Armin Ronacher · committed by Armin Ronacher · parent c2e187b · Browse files · 1 file+29 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+29 added−0 removed

  • other:+29 added−0 removed

1 file+29 added−0 removed

modified:docs/advanced.rst+29 added
61 unmodified lines
62 @cli.command()63 def pop():64 pass6566Token Normalization67-------------------6869.. versionadded:: 2.07071Starting with click 2.0 it's possible to provide a function that is used72for normalizing tokens. Tokens are option names, choice values or command73values. This can be used to implement case insensitive options for74instance.7576In order to use this feature you need to implement a function that77performs the normalization of the token. For instance you could have a78function that converts the token to lowercase. Example:7980.. click:example::8182 CONTEXT_DEFAULTS = dict(token_normalize_func=lambda x: x.lower())8384 @click.command(context_defaults=CONTEXT_DEFAULTS)85 @click.option('--name', default='Pete')86 def cli(name):87 click.echo('Name: %s' % name)8889And how it works on the UI:9091.. click:run::9293 invoke(cli, prog_name='cli', args=['--NAME=Pete'])9495Invoking Other Commands96-----------------------9798Sometimes, it might be interesting to invoke one command from another
93 unmodified lines