forked from JohnAmadeo/lethimcook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
executable file
·34 lines (26 loc) · 957 Bytes
/
Copy pathcli.py
File metadata and controls
executable file
·34 lines (26 loc) · 957 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
#!/usr/bin/env python3
"""Command-line interface for the lethimcook library."""
import sys
from lethimcook import convert_natural
def main():
"""Simple CLI for unit conversions."""
if len(sys.argv) < 2:
print("LetHimCook - Unit Conversion Library")
print("\nUsage:")
print(" python cli.py '2 cups to ml'")
print(" python cli.py 'convert 1 pound to grams'")
print(" python cli.py 'how many ml in 3 teaspoons'")
print("\nSupported units:")
print(" Volume: tsp, tbsp, fl oz, cup, pint, quart, gallon, ml, liter")
print(" Weight: oz, pound, gram, kilogram")
print(" Temperature: fahrenheit, celsius, kelvin")
sys.exit(1)
query = " ".join(sys.argv[1:])
try:
result = convert_natural(query)
print(result)
except ValueError as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()