Skip to content

Commit 0be2bd3

Browse files
authored
Don't include envvar in error hint when envvar not configured (#2972)
2 parents c88f333 + d1f8651 commit 0be2bd3

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Unreleased
1515
screen. Refs :issue:`2911` :pr:`3004`
1616
- Fix completion for the Z shell (``zsh``) for completion items containing
1717
colons. :issue:`2703` :pr:`2846`
18+
- Don't include envvar in error hint when not configured. :issue:`2971` :pr:`2972`
1819
- Fix a rare race in ``click.testing.StreamMixer``'s finalization that manifested
1920
as a ``ValueError`` on close in a multi-threaded test session.
2021
:issue:`2993` :pr:`2991`

src/click/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2682,7 +2682,7 @@ def to_info_dict(self) -> dict[str, t.Any]:
26822682

26832683
def get_error_hint(self, ctx: Context) -> str:
26842684
result = super().get_error_hint(ctx)
2685-
if self.show_envvar:
2685+
if self.show_envvar and self.envvar is not None:
26862686
result += f" (env var: '{self.envvar}')"
26872687
return result
26882688

tests/test_options.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,13 @@ def test_missing_envvar(runner):
677677
assert result.exit_code == 2
678678
assert "Error: Missing option '--foo' (env var: 'bar')." in result.output
679679

680+
cli = click.Command(
681+
"cli", params=[click.Option(["--foo"], show_envvar=True, required=True)]
682+
)
683+
result = runner.invoke(cli)
684+
assert result.exit_code == 2
685+
assert "Error: Missing option '--foo'." in result.output
686+
680687

681688
def test_case_insensitive_choice(runner):
682689
@click.command()

0 commit comments

Comments
 (0)