Coverage for docs_src/options_autocompletion/tutorial003.py: 100%
12 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_names = ["Camila", "Carlos", "Sebastian"] 1habcdefg
6def complete_name(incomplete: str): 1habcdefg
7 completion = [] 1habcdefg
8 for name in valid_names: 1habcdefg
9 if name.startswith(incomplete): 1habcdefg
10 completion.append(name) 1habcdefg
11 return completion 1habcdefg
14app = typer.Typer() 1habcdefg
17@app.command() 1habcdefg
18def main( 1abcdefg
19 name: str = typer.Option(
20 "World", help="The name to say hi to.", autocompletion=complete_name
21 ),
22):
23 print(f"Hello {name}") 1habcdefg
26if __name__ == "__main__": 1habcdefg
27 app() 1habcdefg