Skip to content
Myr

Improved documentation of token normalization

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

authored by Kevin Yap · committed by Kevin Yap · parent 254bc79 · Browse files · 1 file+13 added−14 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+13 added−14 removed

  • other:+13 added−14 removed

1 file+13 added−14 removed

modified:docs/advanced.rst+13 added-14 removed
2 unmodified lines
34.. currentmodule:: click56In addition to common functionality that is implemented in the library7itself, there are countless of patterns that can be implemented by extending8click. This page should give some inspiration of what can be9accomplished.7itself, there are countless patterns that can be implemented by extending8click. This page should give some insight into what can be accomplished.910.. _aliases:1112Command Aliases13---------------1415Many tools support aliases for commands. For instance, you can configure16``git`` to accept ``git ci`` as alias for ``git commit``. Other tools18also support auto discovery for aliases by automatically shortening them.17also support auto-discovery for aliases by automatically shortening them.1820Click does not support this out of the box but it's very easy to customize19Click does not support this out of the box, but it's very easy to customize20the :class:`Group` or any other :class:`MultiCommand` to provide this21functionality.2223As explained in :ref:`custom-multi-commands`, a multi command can provide
2 unmodified lines
26to override the latter as you generally don't want to enumerate the27aliases on the help page in order to avoid confusion.2829This following example implements a subclass of :class:`Group` that31accepts a prefix for a command. If there were a command called32``push``, it would accept ``pus`` as an alias if it was unique:30accepts a prefix for a command. If there were a command called ``push``,31it would accept ``pus`` as an alias (so long as it was unique):3233.. click:example::3435 class AliasedGroup(click.Group):
30 unmodified lines
66-------------------6768.. versionadded:: 2.06971Starting 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 for70Starting with click 2.0, it's possible to provide a function that is used71for normalizing tokens. Tokens are option names, choice values, or command72values. This can be used to implement case insensitive options, for73instance.7476In 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:75In order to use this feature, the context needs to be passed a function that76performs the normalization of the token. For instance, you could have a77function that converts the token to lowercase:7879.. click:example::8081 CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())
2 unmodified lines
84 @click.option('--name', default='Pete')85 def cli(name):86 click.echo('Name: %s' % name)8789And how it works on the UI:88And how it works on the command line:8990.. click:run::9192 invoke(cli, prog_name='cli', args=['--NAME=Pete'])
98 unmodified lines