|
1 | 1 | # stdlib |
2 | 2 | import sys |
3 | | -from typing import Iterable |
| 3 | +from typing import Iterable, List |
4 | 4 |
|
5 | 5 | # 3rd party |
6 | 6 | import click |
|
10 | 10 |
|
11 | 11 | # this package |
12 | 12 | from consolekit import click_command |
| 13 | +import consolekit |
13 | 14 | from consolekit.options import ( |
14 | 15 | ChoiceOption, |
15 | 16 | DescribedArgument, |
@@ -353,7 +354,7 @@ def test_lazy_choice( |
353 | 354 | cli_runner: CliRunner, |
354 | 355 | ): |
355 | 356 |
|
356 | | - def expensive_operation(): |
| 357 | + def expensive_operation() -> List[str]: |
357 | 358 | print("Performing expensive operation to get choices.") |
358 | 359 | return ["Radio 1", "Radio 2", "Radio 3"] |
359 | 360 |
|
@@ -422,6 +423,26 @@ def main(station: str) -> None: |
422 | 423 | assert result.exit_code == 0 |
423 | 424 | assert result.stdout.rstrip() == "Tuning to station: Radio 1" |
424 | 425 |
|
| 426 | + @consolekit.option( |
| 427 | + "-s", |
| 428 | + "--station", |
| 429 | + help="The station to play.", |
| 430 | + type=click.Choice(["Radio 1", "Radio 2", "Radio 3"], case_sensitive=False), |
| 431 | + cls=PromptOption, |
| 432 | + prompt="Select a station", |
| 433 | + ) |
| 434 | + @click_command() |
| 435 | + def main2(station: str) -> None: |
| 436 | + print(f"Tuning to station: {station}") |
| 437 | + |
| 438 | + result = cli_runner.invoke(main2, input="Radio 4\nRadio 2\n") |
| 439 | + assert result.exit_code == 0 |
| 440 | + advanced_file_regression.check(result.stdout.rstrip()) |
| 441 | + |
| 442 | + result = cli_runner.invoke(main2, args=["--station", "Radio 1"]) |
| 443 | + assert result.exit_code == 0 |
| 444 | + assert result.stdout.rstrip() == "Tuning to station: Radio 1" |
| 445 | + |
425 | 446 |
|
426 | 447 | @pytest.mark.parametrize( |
427 | 448 | "click_version", |
|
0 commit comments