-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_81.py
More file actions
34 lines (24 loc) · 757 Bytes
/
Copy pathexample_81.py
File metadata and controls
34 lines (24 loc) · 757 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
from enum import Enum
from typing import List
import typer
from typing_extensions import Annotated
"""See https://typer.tiangolo.com/tutorial/parameter-types/enum/"""
"""
CLI options - Enum Choices
List of Enum values
A CLI parameter can also take a list of `Enum` values:
"""
class Food(str, Enum):
food_1 = "Eggs"
food_2 = "Bacon"
food_3 = "Cheese"
def main(groceries: Annotated[List[Food], typer.Option()] = [Food.food_1, Food.food_3]):
"""
python main.py --help
python main.py (try with defaults)
python main.py --groceries Eggs
python main.py --groceries Eggs --groceries Cheese
"""
print(f"Buying groceries: {', '.join([f.value for f in groceries])}")
if __name__ == "__main__":
typer.run(main)