-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_71.py
More file actions
28 lines (19 loc) · 760 Bytes
/
Copy pathexample_71.py
File metadata and controls
28 lines (19 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import typer
from typing_extensions import Annotated
"""See https://typer.tiangolo.com/tutorial/parameter-types/number/"""
"""
CLI Parameter Types Counter CLI options
You can make a CLI option work as a counter with the `counter` parameter:
"""
def main(verbose: Annotated[int, typer.Option("--verbose", "-v", count=True)] = 0):
"""
It means that the CLI option will be like a boolean flag, e.g. `--verbose`
And the value you receive in the function will be the amount of times that
`--verbose` was added:
E.g try `python example_71.py --verbose --verbose`
(or `python example_71.py -v -v -v`)
(or `python example_71.py -vvv`)
"""
print(f"Verbose level is {verbose}")
if __name__ == "__main__":
typer.run(main)