Skip to content
Myr

Merge branch 'main' into dual-flags-competition

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

authored by Rowlando13 · committed by GitHub · parents 0f71fe7, 3619563 · Browse files · 3 files+75 added−28 removed
This commit

State

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

Diff stats

3 files+75 added−28 removed

  • other:+75 added−28 removed

3 files+75 added−28 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
516 unmodified lines
modified:src/click/core.py+26 added-28 removed
91 unmodified lines
9293 raise RuntimeError(message)949596def _format_deprecated_label(deprecated: bool | str) -> str:97 """Return the parenthesized deprecation label shown in help text."""98 label = _("deprecated").upper()99 if isinstance(deprecated, str):100 return f"({label}: {deprecated})"101 return f"({label})"102103104def _format_deprecated_suffix(deprecated: bool | str) -> str:105 """Return the trailing reason for a ``DeprecationWarning`` message,106 prefixed with a space, or an empty string when no reason was given.107 """108 if isinstance(deprecated, str):109 return f" {deprecated}"110 return ""111112113def batch(iterable: cabc.Iterable[V], batch_size: int) -> list[tuple[V, ...]]:114 return list(zip(*repeat(iter(iterable), batch_size), strict=False))115116
1041 unmodified lines
1158 else:1159 text = ""11601161 if self.deprecated:1145 localised_deprectated = _("deprecated").upper()1146 deprecated_message = (1147 f"({localised_deprectated}: {self.deprecated})"1148 if isinstance(self.deprecated, str)1149 else f"({localised_deprectated})"1150 )1151 text = f"{_(text)} {deprecated_message}"1162 text = f"{_(text)} {_format_deprecated_label(self.deprecated)}"11631164 return text.strip()11651166 def format_help(self, ctx: Context, formatter: HelpFormatter) -> None:
21 unmodified lines
1188 else:1189 text = ""11901191 if self.deprecated:1181 localised_deprectated = _("deprecated").upper()1182 deprecated_message = (1183 f"({localised_deprectated}: {self.deprecated})"1184 if isinstance(self.deprecated, str)1185 else f"({localised_deprectated})"1186 )1187 text = f"{_(text)} {deprecated_message}"1192 text = f"{_(text)} {_format_deprecated_label(self.deprecated)}"11931194 if text:1195 formatter.write_paragraph()1196
98 unmodified lines
1295 """Given a context, this invokes the attached callback (if it exists)1296 in the right way.1297 """1298 if self.deprecated:1294 extra_message = (1295 f" {self.deprecated}" if isinstance(self.deprecated, str) else ""1296 )1299 message = _(1300 "DeprecationWarning: The command {name!r} is deprecated.{extra_message}"1299 ).format(name=self.name, extra_message=extra_message)1301 ).format(1302 name=self.name,1303 extra_message=_format_deprecated_suffix(self.deprecated),1304 )1305 echo(style(message, fg="red"), err=True)13061307 if self.callback is not None:1308 return ctx.invoke(self.callback, **ctx.params)
1305 unmodified lines
2614 self.deprecated2615 and value is not UNSET2616 and source < ParameterSource.DEFAULT_MAP2617 ):2613 extra_message = (2614 f" {self.deprecated}" if isinstance(self.deprecated, str) else ""2615 )2618 message = _(2619 "DeprecationWarning: The {param_type} {name!r} is deprecated."2620 "{extra_message}"2621 ).format(2622 param_type=self.param_type_name,2623 name=self.human_readable_name,2622 extra_message=extra_message,2624 extra_message=_format_deprecated_suffix(self.deprecated),2625 )2626 echo(style(message, fg="red"), err=True)26272628 # Process the value through the parameter's type.
188 unmodified lines
2817 else:2818 prompt_text = prompt28192820 if deprecated:2819 deprecated_message = (2820 f"(DEPRECATED: {deprecated})"2821 if isinstance(deprecated, str)2822 else "(DEPRECATED)"2823 )2824 help = help + deprecated_message if help is not None else deprecated_message2821 label = _format_deprecated_label(deprecated)2822 help = f"{help} {label}" if help is not None else label28232824 self.prompt = prompt_text2825 self.confirmation_prompt = confirmation_prompt2826 self.prompt_required = prompt_required
709 unmodified lines
modified:CHANGES.rst+7 added
63 unmodified lines
64 within ``ParameterSource.DEFAULT``, an option that received an explicit65 ``default=`` keyword wins over a sibling whose default was auto-derived.66 The 8.3.x first-wins fallback for remaining ties was reverted to the67 pre-8.3.x last-wins fallback. :issue:`3403` :pr:`3404`68- Fix missing space between option help text and the ``(DEPRECATED)``69 label, and localize the option label so it matches the command label.70 The label and the ``DeprecationWarning`` reason suffix are now produced71 by shared helpers. :pr:`3423`72- Document short option stacking (``-abc`` is parsed as ``-a -b -c``) and73 clarify that multi-character short option names are not supported.74 :issue:`2779` :pr:`3431`7576Version 8.3.377-------------78
1364 unmodified lines