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