Skip to content

Commit

Permalink
Avoid need to provide list to custom_choices.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauvilsa committed Apr 27, 2023
1 parent 4e735ea commit 841b33c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions shtab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from string import Template
from typing import Any, Dict, List
from typing import Optional as Opt
from typing import Sequence, Union
from typing import Union

# version detector. Precedence: installed dist, git, 'UNKNOWN'
try:
Expand Down Expand Up @@ -112,8 +112,8 @@ def __lt__(self, other: object) -> bool:


class CustomChoices:
def __init__(self, choices: Sequence[str]) -> None:
self.choices = tuple(choices)
def __init__(self, *choices: str) -> None:
self.choices = choices
assert all(isinstance(c, str) for c in self.choices)

def bash_choices(self, prefix: str, option_string: str) -> str:
Expand All @@ -128,8 +128,8 @@ def tcsh_choices(self) -> str:
return "(" + " ".join(self.choices) + ")"


def custom_choices(choices: List[str]) -> CustomChoices:
return CustomChoices(choices)
def custom_choices(*choices: str) -> CustomChoices:
return CustomChoices(*choices)


class Optional:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_shtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_subparser_custom_complete(shell, caplog):
def test_custom_choices(shell, caplog):
parser = ArgumentParser(prog="test")
action = parser.add_argument("--optA")
action.complete = shtab.custom_choices(["yes", "no", "maybe"])
action.complete = shtab.custom_choices("yes", "no", "maybe")
with caplog.at_level(logging.INFO):
completion = shtab.complete(parser, shell=shell)
print(completion)
Expand Down

0 comments on commit 841b33c

Please sign in to comment.