-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.py
More file actions
48 lines (38 loc) · 956 Bytes
/
cli.py
File metadata and controls
48 lines (38 loc) · 956 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
36
37
38
39
40
41
42
43
44
45
46
47
48
import sys
from interpreter.runner import run_program
VERSION = "Pearlen 0.1.1 Alpha"
def show_help():
print("""
Pearlen CLI
Usage:
pearl <file.pearl> Run a Pearlen file
pearl -i Interactive mode
pearl -v Show version
""")
def run_file(path):
try:
with open(path, "r") as f:
code = f.read()
run_program(code)
except FileNotFoundError:
print(f"Error: file '{path}' not found.")
def repl():
print("Pearlen REPL — type 'exit' to quit")
while True:
line = input("pearlen> ").strip()
if line == "exit":
break
run_program(line)
if __name__ == "__main__":
if len(sys.argv) < 2:
show_help()
sys.exit()
cmd = sys.argv[1]
if cmd.endswith(".pearl"):
run_file(cmd)
elif cmd == "-i":
repl()
elif cmd == "-v":
print(VERSION)
else:
show_help()