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
Provenance
- Commit
6358f9f- Tree
e592d1c- Author
Kevin Yap <me@kevinyap.ca>- Committer
Kevin Yap <me@kevinyap.ca>- Parent
254bc79
1 file changed+13 added−14 removed
modified:docs/advanced.rst+13 added-14 removed
2 unmodified lines3 4 .. currentmodule:: click5 6 In addition to common functionality that is implemented in the library7-itself, there are countless of patterns that can be implemented by extending8-click. This page should give some inspiration of what can be9-accomplished.7+itself, there are countless patterns that can be implemented by extending8+click. This page should give some insight into what can be accomplished.9 10 .. _aliases:11 12 Command Aliases13 ---------------14 15 Many tools support aliases for commands. For instance, you can configure16 ``git`` to accept ``git ci`` as alias for ``git commit``. Other tools18-also support auto discovery for aliases by automatically shortening them.17+also support auto-discovery for aliases by automatically shortening them.18 20-Click does not support this out of the box but it's very easy to customize19+Click does not support this out of the box, but it's very easy to customize20 the :class:`Group` or any other :class:`MultiCommand` to provide this21 functionality.22 23 As explained in :ref:`custom-multi-commands`, a multi command can provide2 unmodified lines26 to override the latter as you generally don't want to enumerate the27 aliases on the help page in order to avoid confusion.28 29 This following example implements a subclass of :class:`Group` that31-accepts a prefix for a command. If there were a command called32-``push``, it would accept ``pus`` as an alias if it was unique:30+accepts a prefix for a command. If there were a command called ``push``,31+it would accept ``pus`` as an alias (so long as it was unique):32 33 .. click:example::34 35 class AliasedGroup(click.Group):30 unmodified lines66 -------------------67 68 .. versionadded:: 2.069 71-Starting with click 2.0 it's possible to provide a function that is used72-for normalizing tokens. Tokens are option names, choice values or command73-values. This can be used to implement case insensitive options for70+Starting with click 2.0, it's possible to provide a function that is used71+for normalizing tokens. Tokens are option names, choice values, or command72+values. This can be used to implement case insensitive options, for73 instance.74 76-In order to use this feature you need to implement a function that77-performs the normalization of the token. For instance you could have a78-function that converts the token to lowercase. Example:75+In order to use this feature, the context needs to be passed a function that76+performs the normalization of the token. For instance, you could have a77+function that converts the token to lowercase:78 79 .. click:example::80 81 CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())2 unmodified lines84 @click.option('--name', default='Pete')85 def cli(name):86 click.echo('Name: %s' % name)87 89-And how it works on the UI:88+And how it works on the command line:89 90 .. click:run::91 92 invoke(cli, prog_name='cli', args=['--NAME=Pete'])98 unmodified lines