apply review suggestions
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Brian Hall · committed by Brian Hall · parent 74e542e · Browse files · 1 file·+7 added−9 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+7 added−9 removed
- other:+7 added−9 removed
Provenance
- Commit
94715df- Tree
3269d9a- Author
Brian Hall <brian.hall5@yahoo.com>- Committer
Brian Hall <brian.hall5@yahoo.com>- Parent
74e542e
1 file changed+7 added−9 removed
modified:docs/options.md+7 added-9 removed
22 unmodified lines23 ```24 25 ## Option Decorator26 27-The {func}`option()` decorator accepts parameter declarations as positional arguments. Parameter declarations can consist of any number of option names and, optionally, a single identifier matching an argument name in the decorated callback function.27+The {func}`option()` decorator is usually passed two positional arguments: the option name and the decorated function argument name.28 29 ```{eval-rst}30 .. click:example::31 7 unmodified lines39 40 invoke(echo, args=['--help'])41 ```42 43-If an identifier for the callback argument is not declared, then Click will try to infer it. A simple way to name an option is by prepending `--` to the callback argument name and converting underscores to `-`; this ensures that Click can correctly infer the callback argument name. Consequently, {func}`option()` only requires declarations for the option name(s).43+However, if the decorated function argument name is not passed in, then Click will try to infer it. A simple way to name the option so that Click will infer it correctly is by taking the function argument, adding two dashes to the front and converting underscores to dashes.44 45 ```{eval-rst}46 .. click:example::47 6 unmodified lines54 55 invoke(echo, args=['--string-to-echo', 'Hi!'])56 ```57 58-More formally, Click will try to infer the callback argument name as follows:58+More formally, Click will try to infer the decorated function argument name as follows:59 60-1. If a positional argument is a valid [Python identifier], it is chosen.61-2. If multiple positional arguments are prefixed with `--`, the one that was declared first is chosen.60+1. If a positional argument is a valid [Python identifier](https://docs.python.org/3/reference/lexical_analysis.html#identifiers) (and thus does not have dashes), it is chosen.61+2. If multiple positional arguments are prefixed with `--`, the first one declared is chosen.62 3. Otherwise, the first positional argument prefixed with `-` is chosen.63 64-[Python identifier]: https://docs.python.org/3/reference/lexical_analysis.html#identifiers65-64 To get the argument name, the chosen positional argument is converted to lower case, a leading `-` or `--` is removed if found, and any remaining `-` characters are replaced with `_`.65 66 ```{eval-rst}67 .. list-table:: Examples107 unmodified lines175 176 invoke(putitem, args=['--item', 'peter', '1338'])177 ```178 181-By using a tuple literal as `type`, `nargs` gets automatically set to the179+By using a tuple literal as the `type`, `nargs` gets automatically set to the180 length of the tuple and the {class}`click.Tuple` type is automatically181 used. The above example is thus equivalent to this:182 183 ```{eval-rst}269 unmodified lines453 ```454 455 ## Other Prefix Characters456 459-Click can deal with prefix characters besides `-` for options, including `/` and `+`. Note that alternative prefix characters are generally used very sparingly if at all within POSIX.457+Click can deal with prefix characters besides `-` for options, including `/` and `+`, as well as others. Note that alternative prefix characters are generally used very sparingly if at all within POSIX.458 459 ```{eval-rst}460 .. click:example::461 39 unmodified lines