diff --git a/python/src/trezorlib/cli/__init__.py b/python/src/trezorlib/cli/__init__.py index 8a4191a8e..91cd0ce1e 100644 --- a/python/src/trezorlib/cli/__init__.py +++ b/python/src/trezorlib/cli/__init__.py @@ -40,14 +40,20 @@ if TYPE_CHECKING: class ChoiceType(click.Choice): - def __init__(self, typemap: Dict[str, Any]) -> None: + def __init__(self, typemap: Dict[str, Any], case_sensitive: bool = True) -> None: super().__init__(list(typemap.keys())) - self.typemap = typemap + self.case_sensitive = case_sensitive + if case_sensitive: + self.typemap = typemap + else: + self.typemap = {k.lower(): v for k, v in typemap.items()} - def convert(self, value: str, param: Any, ctx: click.Context) -> Any: + def convert(self, value: Any, param: Any, ctx: click.Context) -> Any: if value in self.typemap.values(): return value value = super().convert(value, param, ctx) + if isinstance(value, str) and not self.case_sensitive: + value = value.lower() return self.typemap[value]