Skip to content

Commit c2e5ed1

Browse files
committed
fix(cli): case-insensitive Set yields the canonical spelling
Case-insensitive `Set` now returns the configured (canonical) spelling instead of the lowercased user input, e.g. `Set("TCP", "UDP")("tcp")` now yields "TCP". Assisted-by: ClaudeCode:claude-opus-4.8
1 parent e1610f4 commit c2e5ed1

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

plumbum/cli/switches.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,13 @@ def _call_iter(
555555
for v in value.split(self.csv):
556556
yield from self._call_iter(v.strip(), check_csv=False)
557557

558-
if not self.case_sensitive:
559-
value = value.lower()
558+
cmp_value = value if self.case_sensitive else value.lower()
560559

561560
for opt in self.values:
562561
if isinstance(opt, str):
563-
if not self.case_sensitive:
564-
opt = opt.lower() # noqa: PLW2901
565-
if opt == value or value in self.all_markers:
566-
yield opt # always return original value
562+
cmp_opt = opt if self.case_sensitive else opt.lower()
563+
if cmp_opt == cmp_value or cmp_value in self.all_markers:
564+
yield opt # always return the configured (canonical) value
567565
continue
568566
with contextlib.suppress(ValueError):
569567
yield opt(value)

tests/test_cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ def test_okay(self, capsys):
209209
_, rc = SimpleApp.run(["foo", "--bacon=81", "--csv=all,100"], exit=False)
210210
assert rc == 0
211211
output = capsys.readouterr()
212-
assert "min" in output.out
213-
assert "max" in output.out
212+
# case-insensitive Set yields the canonical (configured) spelling
213+
assert "MIN" in output.out
214+
assert "MAX" in output.out
214215
assert "100" in output.out
215216

216217
_, rc = SimpleApp.run(["foo", "--bacon=81", "--num=MAX"], exit=False)

tests/test_validate.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
from __future__ import annotations
22

33
from plumbum import cli
4+
from plumbum.cli.switches import Set
5+
6+
7+
class TestSet:
8+
def test_case_insensitive_returns_canonical(self):
9+
# Regression: case-insensitive matching must yield the configured
10+
# (canonical) spelling, not the lowercased user input.
11+
s = Set("TCP", "UDP")
12+
assert s("tcp") == "TCP"
13+
assert s("UDP") == "UDP"
414

515

616
class TestValidator:

0 commit comments

Comments
 (0)