Skip to content
Myr

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

2 files+38 added−35 removed

modified:docs/options.rst+26 added-7 removed
11 unmodified lines
1213Name Your Options14-----------------1516The naming rules can be found in :ref:`parameter_names`. In short, you17can refer the option **implicitly** by the dash-prefixed hierarchy. 18Where two dashes comes before a single dash:16Options have a name that will be used as the Python argument name when17calling the decorated function. This can be inferred from the option18names or given explicitly. Names are given as position arguments to the19decorator.2020.. click:example::21A name is chosen in the following order22231. 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.252. If there is at least one name prefixed with two dashes, the first26 one given is used as the name.273. The first name prefixed with one dash is used otherwise.2829To get the Python argument name, the chosen name is converted to lower30case, up to two dashes are removed as the prefix, and other dashes are31converted to underscores.3233.. code-block:: python3435 @click.command()36 @click.option('-s', '--string-to-echo')37 def echo(string_to_echo):38 click.echo(string_to_echo)3927Or, **explicitly**, by giving one non-dash-prefixed argument:40.. code-block:: python4129.. click:example::3042 @click.command()43 @click.option('-s', '--string-to-echo', 'string')44 def echo(string):45 click.echo(string)4647- ``"-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``5455Basic Value Options56-------------------5758The most basic option is a value option. These options accept one
790 unmodified lines
modified:docs/parameters.rst+12 added-28 removed
81 unmodified lines
8283Parameter Names84---------------8586Parameters (both options and arguments) accept a number of positional arguments87which are passed to the command function as parameters. Each string with a88single dash is added as a short argument; each string starting with a double89dash as a long one.86Parameters (both options and arguments) have a name that will be used as87the Python argument name when calling the decorated function with88values.8991If a string is added without any dashes, it becomes the internal parameter name92which is also used as variable name.90Arguments take only one positional name. To provide a different name for91use in help text, see :ref:`doc-meta-variables`.9294If a string contains a single dash and a double dash, the double dash95becomes the internal parameter name.93Options can have many names that may be prefixed with one or two dashes.94Names with one dash are parsed as short options, names with two are95parsed as long options. If a name is not prefixed, it is used as the96Python argument name and not parsed as an option name. Otherwise, the97first name with a two dash prefix is used, or the first with a one dash98prefix if there are none with two. The prefix is removed and dashes are99converted to underscores to get the Python argument name.10097If there are multiple strings that contain a single dash, the first string98becomes the internal name. The same is true if all arguments begin with 99double dashes.101101All dashes after the beginning first two dashes convert to underscores.102103The internal name is converted to lowercase.104105Examples:106107* 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`.117102Implementing Custom Types103-------------------------104105To implement a custom type, you need to subclass the :class:`ParamType`
37 unmodified lines