diff --git a/httpie/cli/utils.py b/httpie/cli/utils.py index ad27da37f7..957baab5a0 100644 --- a/httpie/cli/utils.py +++ b/httpie/cli/utils.py @@ -44,7 +44,6 @@ def __init__( self._help: Optional[str] = None self._obj: Optional[Iterable[T]] = None super().__init__(*args, **kwargs) - self.choices = self def load(self) -> T: if self._obj is None or not self.cache: @@ -76,4 +75,10 @@ def __iter__(self) -> Iterator[T]: return iter(self.load()) def __call__(self, parser, namespace, values, option_string=None): + if self.load() is not None and values not in self.load(): + raise argparse.ArgumentError( + self, + f"invalid choice: {values!r} " + f"(choose from {{{', '.join(str(c) for c in self.load())}}})", + ) setattr(namespace, self.dest, values)