Coverage for docs_src/options_autocompletion/tutorial003_an.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
2from typing_extensions import Annotated 1habcdefg
4valid_names = ["Camila", "Carlos", "Sebastian"] 1habcdefg
7def complete_name(incomplete: str): 1habcdefg
8 completion = [] 1habcdefg
9 for name in valid_names: 1habcdefg
10 if name.startswith(incomplete): 1habcdefg
11 completion.append(name) 1habcdefg
12 return completion 1habcdefg
15app = typer.Typer() 1habcdefg
18@app.command() 1habcdefg
19def main( 1abcdefg
20 name: Annotated[
21 str, typer.Option(help="The name to say hi to.", autocompletion=complete_name)
22 ] = "World",
23):
24 print(f"Hello {name}") 1habcdefg
27if __name__ == "__main__": 1habcdefg
28 app() 1habcdefg