Skip to content

Commit 7dbf7df

Browse files
sirosendavidism
authored andcommitted
Ensure auto_envvar_prefix is always uppercased
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.
1 parent 752c5e4 commit 7dbf7df

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Unreleased
8585
- Document that parameter names are lowercased by default. (`#1055`_)
8686
- 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.
8787
- 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`_)
8889

8990
.. _#202: https://github.com/pallets/click/issues/202
9091
.. _#323: https://github.com/pallets/click/issues/323
@@ -197,6 +198,7 @@ Unreleased
197198
.. _#1058: https://github.com/pallets/click/pull/1058
198199
.. _#1059: https://github.com/pallets/click/pull/1059
199200
.. _#1061: https://github.com/pallets/click/pull/1061
201+
.. _#1105: https://github.com/pallets/click/pull/1105
200202

201203

202204
Version 6.7

click/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def __init__(self, command, parent=None, info_name=None, obj=None,
327327
auto_envvar_prefix = '%s_%s' % (parent.auto_envvar_prefix,
328328
self.info_name.upper())
329329
else:
330-
self.auto_envvar_prefix = auto_envvar_prefix.upper()
330+
auto_envvar_prefix = auto_envvar_prefix.upper()
331331
self.auto_envvar_prefix = auto_envvar_prefix
332332

333333
if color is None and parent is not None:

tests/test_options.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ def cmd(username):
202202
assert 'lambda' not in result.output
203203
assert '(current user)' in result.output
204204

205+
206+
def test_toupper_envvar_prefix(runner):
207+
@click.command()
208+
@click.option('--arg')
209+
def cmd(arg):
210+
click.echo(arg)
211+
212+
result = runner.invoke(cmd, [], auto_envvar_prefix='test',
213+
env={'TEST_ARG': 'foo'})
214+
assert not result.exception
215+
assert result.output == 'foo\n'
216+
217+
205218
def test_nargs_envvar(runner):
206219
@click.command()
207220
@click.option('--arg', nargs=2)

0 commit comments

Comments
 (0)