Skip to content
Myr

context.show_default defaults to parent context

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

authored by Joongi Kim · committed by David Lord · parent 0ad4e79 · Browse files · 3 files+42 added−18 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+42 added−18 removed

  • tests:+14 added−0 removed
  • other:+28 added−18 removed

3 files+42 added−18 removed

modified:src/click/core.py+26 added-18 removed
171 unmodified lines
172173 A context can be used as context manager in which case it will call174 :meth:`close` on teardown.175176 .. versionadded:: 2.0177 Added the `resilient_parsing`, `help_option_names`,178 `token_normalize_func` parameters.179180 .. versionadded:: 3.0181 Added the `allow_extra_args` and `allow_interspersed_args`182 parameters.183184 .. versionadded:: 4.0185 Added the `color`, `ignore_unknown_options`, and186 `max_content_width` parameters.187188 .. versionadded:: 7.1189 Added the `show_default` parameter.190176 :param command: the command class for this context.177 :param parent: the parent context.178 :param info_name: the info name for this invocation. Generally this179 is the most descriptive name for the script or
46 unmodified lines
226 default is autodetection. This is only needed if ANSI227 codes are used in texts that Click prints which is by228 default not the case. This for instance would affect229 help output.245 :param show_default: if True, shows defaults for all options.246 Even if an option is later created with show_default=False,247 this command-level setting overrides it.230 :param show_default: Show defaults for all options. If not set,231 defaults to the value from a parent context. Overrides an232 option's ``show_default`` argument.233234 .. versionchanged:: 8.0235 The ``show_default`` parameter defaults to the value from the236 parent context.237238 .. versionchanged:: 7.1239 Added the ``show_default`` parameter.240241 .. versionchanged:: 4.0242 Added the ``color``, ``ignore_unknown_options``, and243 ``max_content_width`` parameters.244245 .. versionchanged:: 3.0246 Added the ``allow_extra_args`` and ``allow_interspersed_args``247 parameters.248249 .. versionchanged:: 2.0250 Added the ``resilient_parsing``, ``help_option_names``, and251 ``token_normalize_func`` parameters.252 """253254 #: The formatter class to create with :meth:`make_formatter`.255 #:
145 unmodified lines
401402 #: Controls if styling output is wanted or not.403 self.color = color404405 if show_default is None and parent is not None:406 show_default = parent.show_default407408 #: Show option default values when formatting help text.409 self.show_default = show_default410411 self._close_callbacks = []412 self._depth = 0
1802 unmodified lines
modified:tests/test_context.py+14 added
265 unmodified lines
266 assert not result.exception267 assert result.output == "foocmd\n"268269270def test_propagate_show_default_setting(runner):271 """A context's ``show_default`` setting defaults to the value from272 the parent context.273 """274 group = click.Group(275 commands={276 "sub": click.Command("sub", params=[click.Option(["-a"], default="a")]),277 },278 context_settings={"show_default": True},279 )280 result = runner.invoke(group, ["sub", "--help"])281 assert "[default: a]" in result.output282283284def test_exit_not_standalone():285 @click.command()286 @click.pass_context287 def cli(ctx):
72 unmodified lines
modified:CHANGES.rst+2 added
73 unmodified lines
74 curly braces to indicate that one is required (``{a|b|c}``).75 :issue:`1272`76- If only a name is passed to ``option()``, Click suggests renaming it77 to ``--name``. :pr:`1355`78- A context's ``show_default`` parameter defaults to the value from79 the parent context. :issue:`1565`808182Version 7.1.283-------------
635 unmodified lines