Coverage for docs_src/options_autocompletion/tutorial004_an.py: 100%
14 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
1import typer 1habcdefg
2from typing_extensions import Annotated 1habcdefg
4valid_completion_items = [ 1abcdefg
5 ("Camila", "The reader of books."),
6 ("Carlos", "The writer of scripts."),
7 ("Sebastian", "The type hints guy."),
8]
11def complete_name(incomplete: str): 1habcdefg
12 completion = [] 1habcdefg
13 for name, help_text in valid_completion_items: 1habcdefg
14 if name.startswith(incomplete): 1habcdefg
15 completion_item = (name, help_text) 1habcdefg
16 completion.append(completion_item) 1habcdefg
17 return completion 1habcdefg
20app = typer.Typer() 1habcdefg
23@app.command() 1habcdefg
24def main( 1abcdefg
25 name: Annotated[
26 str, typer.Option(help="The name to say hi to.", autocompletion=complete_name)
27 ] = "World",
28):
29 print(f"Hello {name}") 1habcdefg
32if __name__ == "__main__": 1habcdefg
33 app() 1habcdefg