Coverage for docs_src/options_autocompletion/tutorial008_an.py: 100%
16 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 18:26 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 18:26 +0000
1from typing import List 1habcdefg
3import typer 1habcdefg
4from rich.console import Console 1habcdefg
5from typing_extensions import Annotated 1habcdefg
7valid_completion_items = [ 1abcdefg
8 ("Camila", "The reader of books."),
9 ("Carlos", "The writer of scripts."),
10 ("Sebastian", "The type hints guy."),
11]
13err_console = Console(stderr=True) 1habcdefg
16def complete_name(args: List[str], incomplete: str): 1habcdefg
17 err_console.print(f"{args}") 1habcdefg
18 for name, help_text in valid_completion_items: 1habcdefg
19 if name.startswith(incomplete): 1habcdefg
20 yield (name, help_text) 1habcdefg
23app = typer.Typer() 1habcdefg
26@app.command() 1habcdefg
27def main( 1abcdefg
28 name: Annotated[
29 List[str],
30 typer.Option(help="The name to say hi to.", autocompletion=complete_name),
31 ] = ["World"],
32):
33 for n in name: 1habcdefg
34 print(f"Hello {n}") 1habcdefg
37if __name__ == "__main__": 1habcdefg
38 app() 1habcdefg