Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Unreleased

- Document short option combining behavior and clarify that multi-character
short options are not supported. :issue:`2779`
- Fix handling of ``flag_value`` when ``is_flag=False`` to allow such options to be
used without an explicit value. :issue:`3084`

Expand Down
48 changes: 48 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,54 @@ The multiple options format allows options to take an arbitrary number of argume
invoke(commit, args=['-m', 'foo', '-m', 'bar', '-m', 'here'])
```

## Combining Short Options

Short options that consist of a single character can be combined into a
single argument. For example, `-a -b -c` can be written as `-abc`. This
is standard POSIX behavior and applies to any short options, including
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to single short option

flags and options that take values.

```{eval-rst}
.. click:example::

@click.command()
@click.option('-a', is_flag=True)
@click.option('-b', is_flag=True)
@click.option('-c', is_flag=True)
def flags(a, b, c):
click.echo(f"a={a} b={b} c={c}")

.. click:run::

invoke(flags, args=['-a', '-b', '-c'])
invoke(flags, args=['-abc'])
```

When combining options, the last option in the combination can take a
value. The value can be attached directly or passed as the next argument.

```{eval-rst}
.. click:example::

@click.command()
@click.option('-v', is_flag=True)
@click.option('-n', type=int)
def example(v, n):
click.echo(f"v={v} n={n}")

.. click:run::

invoke(example, args=['-vn', '5'])
invoke(example, args=['-vn5'])
```

```{note}
Multi-character short options are not supported. An argument like `-abc`
is always interpreted as the combination of `-a`, `-b`, and `-c`, not as
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove always

a single option named `-abc`. If you need longer option names, use long
options with `--` prefix instead (e.g., `--abc`).
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should read: with the -- prefix


## Counting

To count the occurrence of an option pass in `count=True`. If the option is not passed in, then the count is 0. Counting is commonly used for verbosity.
Expand Down
Loading