Merge pull request #1482 from AlbertUlysses/albert-click
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Parameters Doc Update
authored by David Lord · committed by GitHub · parents 433708e, 145838e · Browse files · 2 files·+38 added−26 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+38 added−26 removed
- other:+38 added−26 removed
Provenance
- Commit
9ba75de- Tree
7b83ff9- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
433708e- Parent 2
145838e
2 files changed+38 added−26 removed
modified:docs/options.rst+26 added-6 removed
11 unmodified lines12 13 Name Your Options14 -----------------15 16-The naming rules can be found in :ref:`parameter_names`. In short, you17-can refer the option **implicitly** by the longest dash-prefixed argument:16+Options have a name that will be used as the Python argument name when17+calling the decorated function. This can be inferred from the option18+names or given explicitly. Names are given as position arguments to the19+decorator.20 19-.. click:example::21+A name is chosen in the following order22 23+1. If a name is not prefixed, it is used as the Python argument name24+ and not treated as an option name on the command line.25+2. If there is at least one name prefixed with two dashes, the first26+ one given is used as the name.27+3. The first name prefixed with one dash is used otherwise.28+29+To get the Python argument name, the chosen name is converted to lower30+case, up to two dashes are removed as the prefix, and other dashes are31+converted to underscores.32+33+.. code-block:: python34+35 @click.command()36 @click.option('-s', '--string-to-echo')37 def echo(string_to_echo):38 click.echo(string_to_echo)39 26-Or, **explicitly**, by giving one non-dash-prefixed argument:40+.. code-block:: python41 28-.. click:example::29-42 @click.command()43 @click.option('-s', '--string-to-echo', 'string')44 def echo(string):45 click.echo(string)46 47+- ``"-f", "--foo-bar"``, the name is ``foo_bar``48+- ``"-x"``, the name is ``x``49+- ``"-f", "--filename", "dest"``, the name is ``dest``50+- ``"--CamelCase"``, the name is ``camelcase``51+- ``"-f", "-fb"``, the name is ``f``52+- ``"--f", "--foo-bar"``, the name is ``f``53+- ``"---f"``, the name is ``_f``54+55 Basic Value Options56 -------------------57 58 The most basic option is a value option. These options accept one790 unmodified linesmodified:docs/parameters.rst+12 added-20 removed
81 unmodified lines82 83 Parameter Names84 ---------------85 86-Parameters (both options and arguments) accept a number of positional arguments87-which are passed to the command function as parameters. Each string with a88-single dash is added as a short argument; each string starting with a double89-dash as a long one.86+Parameters (both options and arguments) have a name that will be used as87+the Python argument name when calling the decorated function with88+values.89 91-If a string is added without any dashes, it becomes the internal parameter name92-which is also used as variable name.90+Arguments take only one positional name. To provide a different name for91+use in help text, see :ref:`doc-meta-variables`.92 94-If all names for a parameter contain dashes, the internal name is generated95-automatically by taking the longest argument and converting all dashes to96-underscores.93+Options can have many names that may be prefixed with one or two dashes.94+Names with one dash are parsed as short options, names with two are95+parsed as long options. If a name is not prefixed, it is used as the96+Python argument name and not parsed as an option name. Otherwise, the97+first name with a two dash prefix is used, or the first with a one dash98+prefix if there are none with two. The prefix is removed and dashes are99+converted to underscores to get the Python argument name.100 98-The internal name is converted to lowercase.101 100-Examples:101-102-* For an option with ``('-f', '--foo-bar')``, the parameter name is `foo_bar`.103-* For an option with ``('-x',)``, the parameter is `x`.104-* For an option with ``('-f', '--filename', 'dest')``, the parameter name is `dest`.105-* For an option with ``('--CamelCaseOption',)``, the parameter is `camelcaseoption`.106-* For an arguments with ``(`foogle`)``, the parameter name is `foogle`. To107- provide a different human readable name for use in help text, see the section108- about :ref:`doc-meta-variables`.109-102 Implementing Custom Types103 -------------------------104 105 To implement a custom type, you need to subclass the :class:`ParamType`37 unmodified lines