-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_40.py
More file actions
35 lines (23 loc) · 788 Bytes
/
Copy pathexample_40.py
File metadata and controls
35 lines (23 loc) · 788 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
29
30
31
32
33
34
35
from typing import Optional
import typer
from typing_extensions import Annotated
"""See https://typer.tiangolo.com/tutorial/options/version/"""
# First version of --version
# You could use a callback to show the version of your CLI program
# and then terminate.
# Note also below that `--version` is declared explicitly because we
# don't want an automatic --no-version.
__version__ = "0.1.0"
def version_callback(value: bool):
if value:
print(f"Awesome CLI Version: {__version__}")
raise typer.Exit()
def main(
name: Annotated[str, typer.Option()] = "World",
version: Annotated[
Optional[bool], typer.Option("--version", callback=version_callback)
] = None,
):
print(f"Hello {name}")
if __name__ == "__main__":
typer.run(main)