Skip to content
Myr

Merge pull request #710 from iffy/show_envvar

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

Add show_envvar for showing environment variables in help

authored by Dan Sully · committed by GitHub · parents 3bf974c, 944cb6f · Browse files · 2 files+41 added−1 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+41 added−1 removed

  • tests:+24 added−0 removed
  • other:+17 added−1 removed

2 files+41 added−1 removed

modified:click/core.py+17 added-1 removed
1443 unmodified lines
1444 All other parameters are passed onwards to the parameter constructor.14451446 :param show_default: controls if the default value should be shown on the1447 help page. Normally, defaults are not shown.1448 :param show_envvar: controls if an environment variable should be shown on1449 the help page. Normally, environment variables1450 are not shown.1451 :param prompt: if set to `True` or a non empty string then the user will be1452 prompted for input. If set to `True` the prompt will be the1453 option name capitalized.1454 :param confirmation_prompt: if set then the value will need to be confirmed
23 unmodified lines
1478 def __init__(self, param_decls=None, show_default=False,1479 prompt=False, confirmation_prompt=False,1480 hide_input=False, is_flag=None, flag_value=None,1481 multiple=False, count=False, allow_from_autoenv=True,1479 type=None, help=None, hidden=False, show_choices=True, **attrs):1482 type=None, help=None, hidden=False, show_choices=True,1483 show_envvar=False, **attrs):1484 default_is_missing = attrs.get('default', _missing) is _missing1485 Parameter.__init__(self, param_decls, type=type, **attrs)14861487 if prompt is True:
38 unmodified lines
1526 self.allow_from_autoenv = allow_from_autoenv1527 self.help = help1528 self.show_default = show_default1529 self.show_choices = show_choices1530 self.show_envvar = show_envvar15311532 # Sanity check for stuff we don't support1533 if __debug__:1534 if self.nargs < 0:
105 unmodified lines
1640 rv.append(_write_opts(self.secondary_opts))16411642 help = self.help or ''1643 extra = []1644 if self.show_envvar:1645 envvar = self.envvar1646 if envvar is None:1647 if self.allow_from_autoenv and \1648 ctx.auto_envvar_prefix is not None:1649 envvar = '%s_%s' % (ctx.auto_envvar_prefix, self.name.upper())1650 if envvar is not None:1651 extra.append('env var: %s' % (1652 ', '.join('%s' % d for d in envvar)1653 if isinstance(envvar, (list, tuple))1654 else envvar, ))1655 if self.default is not None and self.show_default:1656 extra.append('default: %s' % (1657 ', '.join('%s' % d for d in self.default)1658 if isinstance(self.default, (list, tuple))
130 unmodified lines
modified:tests/test_options.py+24 added
196 unmodified lines
197 assert not result.exception198 assert result.output == 'x|1\ny|2\n'199200201def test_show_envvar(runner):202 @click.command()203 @click.option('--arg1', envvar='ARG1',204 show_envvar=True)205 def cmd(arg):206 pass207208 result = runner.invoke(cmd, ['--help'])209 assert not result.exception210 assert 'ARG1' in result.output211212213def test_show_envvar_auto_prefix(runner):214 @click.command()215 @click.option('--arg1', show_envvar=True)216 def cmd(arg):217 pass218219 result = runner.invoke(cmd, ['--help'],220 auto_envvar_prefix='TEST')221 assert not result.exception222 assert 'TEST_ARG1' in result.output223224225def test_custom_validation(runner):226 def validate_pos_int(ctx, param, value):227 if value < 0:228 raise click.BadParameter('Value needs to be positive')
188 unmodified lines