Skip to content
Myr

ignore set empty environment variable

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

authored by Jimmy Zeng · committed by David Lord · parent 278a054 · Browse files · 3 files+27 added−8 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+27 added−8 removed

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

3 files+27 added−8 removed

modified:click/core.py+14 added-7 removed
1321 unmodified lines
1322 intentionally not finalized.13231324 Some settings are supported by both options and arguments.13251326 .. versionchanged:: 2.01327 Changed signature for parameter callback to also be passed the1328 parameter. In Click 2.0, the old callback format will still work,1329 but it will raise a warning to give you change to migrate the1330 code easier.13311326 :param param_decls: the parameter declarations for this option or1327 argument. This is a list of flags or argument1328 names.1329 :param type: the type that should be used. Either a :class:`ParamType`
19 unmodified lines
1349 should not be set for arguments or it will inverse the1350 order of processing.1351 :param envvar: a string or list of strings that are environment variables1352 that should be checked.13531354 .. versionchanged:: 7.11355 Empty environment variables are ignored rather than taking the1356 empty string value. This makes it possible for scripts to clear1357 variables if they can't unset them.13581359 .. versionchanged:: 2.01360 Changed signature for parameter callback to also be passed the1361 parameter. The old callback format will still work, but it will1362 raise a warning to give you a chance to migrate the code easier.1363 """1364 param_type_name = 'parameter'13651366 def __init__(self, param_decls=None, type=None, required=False,
119 unmodified lines
1486 rv = os.environ.get(envvar)1487 if rv is not None:1488 return rv1489 else:1486 return os.environ.get(self.envvar)1490 rv = os.environ.get(self.envvar)14911492 if rv != "":1493 return rv14941495 def value_from_envvar(self, ctx):1496 rv = self.resolve_envvar_value(ctx)1497 if rv is not None and self.nargs != 1:1498 rv = self.type.split_envvar_value(rv)
395 unmodified lines
modified:tests/test_options.py+11 added
111 unmodified lines
112 assert result.exception113 assert 'Error: Missing option "-m" / "--message".' in result.output114115116def test_empty_envvar(runner):117 @click.command()118 @click.option('--mypath', type=click.Path(exists=True), envvar='MYPATH')119 def cli(mypath):120 click.echo('mypath: %s' % mypath)121122 result = runner.invoke(cli, [], env={'MYPATH': ''})123 assert result.exit_code == 0124 assert result.output == 'mypath: None\n'125126127def test_multiple_envvar(runner):128 @click.command()129 @click.option('--arg', multiple=True)130 def cmd(arg):
385 unmodified lines
modified:CHANGES.rst+2 added-1 removed
23 unmodified lines
24- Add ``no_args_is_help`` option to ``click.Command``, defaults to25 False :pr:`1167`26- Add ``show_defaults`` parameter to ``Context`` to enable showing27 defaults globally. :issue:`1018`28- Handle ``env MYPATH=''`` as though the option were not passed.29 :issue:`1196`302931Version 7.032-----------3334Released 2018-09-25
538 unmodified lines