This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
starklings.py
76 lines (63 loc) · 1.6 KB
/
starklings.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from argparse import ArgumentParser
import asyncio
import os
from pathlib import Path
from rich.traceback import install
from src import cli
from src.config import current_working_directory
install(show_locals=True)
def is_valid_file(parser, arg):
file_path = Path(arg).resolve()
if not file_path.exists():
file_path = current_working_directory / arg
if not file_path.exists():
return parser.error(f"The file {arg} does not exist!")
return file_path
script_root = Path(os.getcwd())
root_parser = ArgumentParser()
root_parser.add_argument(
"--version",
"-V",
help="Show version-related data",
action="store_true",
)
root_parser.add_argument(
"--verify",
"-v",
metavar="relative_path_to_exercise",
help="Verify a single exercise",
type=lambda x: is_valid_file(root_parser, x),
)
root_parser.add_argument(
"--watch",
"-w",
help="Watch edited files and verify them",
action="store_true",
)
root_parser.add_argument(
"--solution",
"-s",
metavar="relative_path_to_exercise",
help="Provide a solution for an exercise",
type=lambda x: is_valid_file(root_parser, x),
)
root_parser.add_argument(
"--display-course",
"-d",
action="store_true",
help="Display the course content",
)
root_parser.add_argument(
"--login",
"-l",
help="Login with Github",
action="store_true",
)
try:
asyncio.run(cli(root_parser.parse_args()))
except Exception as error:
print(
"Unexpected Starklings error. Report it here:\n"
+ "https://github.com/onlydustxyz/starklings/issues\n"
)
raise error