Skip to content
Myr

Document short option stacking behavior

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Closes #2779

authored by Kevin Deldycke · committed by Kevin Deldycke · parent 0039359 · Browse files · 2 files+45 added−0 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+45 added−0 removed

  • other:+45 added−0 removed

2 files+45 added−0 removed

modified:docs/options.md+42 added
228 unmodified lines
229230 invoke(commit, args=['-m', 'foo', '-m', 'bar', '-m', 'here'])231```232233## Combining short options234235Short options made of a single character can be combined into one argument: `-abc` is equivalent to `-a -b -c`. This is the standard POSIX behavior for short option stacking, and it is the reason a repeated flag like `-vvv` works with the [Counting](#counting) feature.236237```{eval-rst}238.. click:example::239240 @click.command()241 @click.option('-a', is_flag=True)242 @click.option('-b', is_flag=True)243 @click.option('-c', is_flag=True)244 def cli(a, b, c):245 click.echo(f"a={a} b={b} c={c}")246247.. click:run::248249 invoke(cli, args=['-a', '-b', '-c'])250 invoke(cli, args=['-abc'])251```252253If the last option in the combination takes a value, the value can either follow as the next argument or be attached directly:254255```{eval-rst}256.. click:example::257258 @click.command()259 @click.option('-v', is_flag=True)260 @click.option('-n', type=int)261 def cli(v, n):262 click.echo(f"v={v} n={n}")263264.. click:run::265266 invoke(cli, args=['-v', '-n', '5'])267 invoke(cli, args=['-vn', '5'])268 invoke(cli, args=['-vn5'])269```270271```{note}272Multi-character short option names are not supported. An argument like `-dbg` is interpreted as the combination of `-d`, `-b`, and `-g`, so Click reports `No such option: -d` if `-d` is not declared. For longer option names, use a long option with the `--` prefix (like `--debug`).273```274275## Counting276277To count the occurrence of an option, set `count=True`. If the option is not278passed on the command line, then the count is 0. Counting is commonly used for
400 unmodified lines
modified:CHANGES.rst+3 added
55 unmodified lines
56- Show custom error messages from types when :func:`prompt` with57 ``hide_input=True`` fails validation, instead of always showing a58 generic message. Built-in type messages mask the input value.59 :issue:`2809` :pr:`3256`60- Document short option stacking (``-abc`` is parsed as ``-a -b -c``) and61 clarify that multi-character short option names are not supported.62 :issue:`2779` :pr:`3431`6364Version 8.3.365-------------66
1364 unmodified lines