more clarity for parameter name docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent d693b6f · Browse files · 2 files·+38 added−35 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−35 removed
- other:+38 added−35 removed
Provenance
- Commit
145838e- Tree
7b83ff9- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
d693b6f
2 files changed+38 added−35 removed
modified:docs/options.rst+26 added-7 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 dash-prefixed hierarchy. 18-Where two dashes comes before a single dash: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 20-.. 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 27-Or, **explicitly**, by giving one non-dash-prefixed argument:40+.. code-block:: python41 29-.. click:example::30-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-28 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 a string contains a single dash and a double dash, the double dash95-becomes the internal parameter name.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 97-If there are multiple strings that contain a single dash, the first string98-becomes the internal name. The same is true if all arguments begin with 99-double dashes.101 101-All dashes after the beginning first two dashes convert to underscores.102-103-The internal name is converted to lowercase.104-105-Examples:106-107-* For an option with ``('-f', '--foo-bar')``, the parameter name is `foo_bar`.108-* For an option with ``('-x',)``, the parameter name is `x`.109-* For an option with ``('-f', '--filename', 'dest')``, the parameter name is `dest`.110-* For an option with ``('--CamelCaseOption',)``, the parameter name is `camelcaseoption`.111-* For an option with ``('-f', '-foo-bar')``, the parameter name is `f`.112-* For an option with ``('--f', '--foo-bar')``, the parameter name is `f`.113-* For an option with ``('---f')``, the parameter name is `_f`.114-* For an arguments with ``(`foogle`)``, the parameter name is `foogle`. To115- provide a different human readable name for use in help text, see the section116- about :ref:`doc-meta-variables`.117-102 Implementing Custom Types103 -------------------------104 105 To implement a custom type, you need to subclass the :class:`ParamType`37 unmodified lines