Skip to content
Myr

Merge pull request #1225 from antimirov/click-1018-show-defaults

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

Showing defaults globally

authored by Stephen Rosen · committed by GitHub · parents 30ce8ff, 9df9b07 · Browse files · 2 files+24 added−2 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+24 added−2 removed

  • tests:+16 added−0 removed
  • other:+8 added−2 removed

2 files+24 added−2 removed

modified:click/core.py+8 added-2 removed
206 unmodified lines
207 default is autodetection. This is only needed if ANSI208 codes are used in texts that Click prints which is by209 default not the case. This for instance would affect210 help output.211 :param show_default: if True, shows defaults for all options.212 Even if an option is later created with show_default=False,213 this command-level setting overrides it.214 """215216 def __init__(self, command, parent=None, info_name=None, obj=None,217 auto_envvar_prefix=None, default_map=None,218 terminal_width=None, max_content_width=None,219 resilient_parsing=False, allow_extra_args=None,220 allow_interspersed_args=None,221 ignore_unknown_options=None, help_option_names=None,219 token_normalize_func=None, color=None):222 token_normalize_func=None, color=None, show_default=None):223 #: the parent context or `None` if none exists.224 self.parent = parent225 #: the :class:`Command` for this context.226 self.command = command
112 unmodified lines
339340 #: Controls if styling output is wanted or not.341 self.color = color342343 self.show_default = show_default344345 self._close_callbacks = []346 self._depth = 0347348 def __enter__(self):
1378 unmodified lines
1727 extra.append('env var: %s' % (1728 ', '.join('%s' % d for d in envvar)1729 if isinstance(envvar, (list, tuple))1730 else envvar, ))1726 if self.default is not None and self.show_default:1731 if self.default is not None and \1732 (self.show_default or ctx.show_default):1733 if isinstance(self.show_default, string_types):1734 default_string = '({})'.format(self.show_default)1735 elif isinstance(self.default, (list, tuple)):1736 default_string = ', '.join('%s' % d for d in self.default)
135 unmodified lines
modified:tests/test_formatting.py+16 added
295 unmodified lines
296 '',297 'Options:',298 ' --help Show this message and exit.',299 ]300301302def test_global_show_default(runner):303 @click.command(context_settings=dict(show_default=True))304 @click.option("-f", "in_file", default="out.txt", help="Output file name")305 def cli():306 pass307308 result = runner.invoke(cli, ['--help'],)309 assert result.output.splitlines() == [310 'Usage: cli [OPTIONS]',311 '',312 'Options:',313 ' -f TEXT Output file name [default: out.txt]',314 ' --help Show this message and exit. [default: False]'315 ]