Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion httpie/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Loading