-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_34.py
More file actions
37 lines (25 loc) · 1.04 KB
/
Copy pathexample_34.py
File metadata and controls
37 lines (25 loc) · 1.04 KB
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
36
37
import typer
from typing_extensions import Annotated
"""See https://typer.tiangolo.com/tutorial/options/name/"""
# CLI Option Short Names
"""
The excellent Typer documentation has a few notes around this. See the link
above. Here is a summary
- Short Names comprise of a dash and a single letter e.g `-n`
- Multiple Short Names can be grouped with a single dash e.g -np (== -pn)
- If you have a CLI option with a value (as opposed to a boolean) it can
be grouped but the one with the value must be the last so it can receive
the value e.g. in
tar -xvf myproject.tar.gz
x and v are booleans. f is a filename and takes the value myproject.tar.gz
- To define a short name, add it into `typer.Option` along with the default
name or a custom name.
- If you just put the short name, that is all that will be available
"""
def main(user_name: Annotated[str, typer.Option("--name", "-n")]):
"""
Overwrite the CLI option name and also add a short name
"""
print(f"Hello {user_name}")
if __name__ == "__main__":
typer.run(main)