Skip to content
Myr

Ensure auto_envvar_prefix is always uppercased

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

Add a failing test and the modification to make it pass. Given a lowercase auto_envvar_prefix, it's clearly supposed to be converted to uppercase by the Context init. However, there's a slight bug -- the prefix is uppercased, then reset to its prior value. Test that setting a prefix of `test` results in `--arg` using `TEST_ARG` (all uppercase). Fix `Context.__init__` to do the right thing.

authored by Stephen Rosen · committed by David Lord · parent 752c5e4 · Browse files · 3 files+16 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

3 files+16 added−1 removed

  • tests:+13 added−0 removed
  • other:+3 added−1 removed

3 files+16 added−1 removed

modified:click/core.py+1 added-1 removed
325 unmodified lines
326 self.info_name is not None:327 auto_envvar_prefix = '%s_%s' % (parent.auto_envvar_prefix,328 self.info_name.upper())329 else:330 self.auto_envvar_prefix = auto_envvar_prefix.upper()330 auto_envvar_prefix = auto_envvar_prefix.upper()331 self.auto_envvar_prefix = auto_envvar_prefix332333 if color is None and parent is not None:334 color = parent.color
1519 unmodified lines
modified:tests/test_options.py+13 added
200 unmodified lines
201 assert '--username' in result.output202 assert 'lambda' not in result.output203 assert '(current user)' in result.output204205206def test_toupper_envvar_prefix(runner):207 @click.command()208 @click.option('--arg')209 def cmd(arg):210 click.echo(arg)211212 result = runner.invoke(cmd, [], auto_envvar_prefix='test',213 env={'TEST_ARG': 'foo'})214 assert not result.exception215 assert result.output == 'foo\n'216217218def test_nargs_envvar(runner):219 @click.command()220 @click.option('--arg', nargs=2)221 def cmd(arg):
268 unmodified lines
modified:CHANGES.rst+2 added
83 unmodified lines
84- Use Python sorting order for ZSH completions. (`#1047`_, `#1059`_)85- Document that parameter names are lowercased by default. (`#1055`_)86- Subcommands that are named by the function now automatically have the underscore replaced with a dash. If you register a function named ``my_command`` it becomes ``my-command`` in the command line interface.87- Hide hidden commands and options from completion. (`#1058`_, `#1061`_)88- Fix issue where a lowercase ``auto_envvar_prefix`` would not be converted to uppercase. (`#1105`_)8990.. _#202: https://github.com/pallets/click/issues/20291.. _#323: https://github.com/pallets/click/issues/32392.. _#334: https://github.com/pallets/click/issues/334
104 unmodified lines
197.. _#1055: https://github.com/pallets/click/pull/1055198.. _#1058: https://github.com/pallets/click/pull/1058199.. _#1059: https://github.com/pallets/click/pull/1059200.. _#1061: https://github.com/pallets/click/pull/1061201.. _#1105: https://github.com/pallets/click/pull/1105202203204Version 6.7205-----------
343 unmodified lines