-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (51 loc) · 1.81 KB
/
main.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
from GymRepository import *
import sys
from datetime import datetime
from traceback import print_exception
from ArgumentParsers import *
def log_exception(exc_type, exc_value, exc_traceback):
with open(GymRepository.log_file, 'r') as f:
logs = f.read()
with open(GymRepository.log_file, 'w') as f:
time = datetime.now().strftime("%Y-%m-%D %H:%M:%S")
f.write(f"[{time}]\n\n")
print_exception(exc_type, exc_value, exc_traceback, file=f)
f.write('-' * 30 + '\n')
f.write(logs)
print("\nAn error has occurred! "
"\nWe as the developer team have already "
"\nbeen notified and work on fixing it.")
sys.excepthook = log_exception
def main(args):
if len(args) == 1:
print("Welcome to the gym!")
print("Time to show 'em commits who's the boss, right?")
print("To see the list of available commands, you can use \"gym help\"")
return
command = args[1]
flags = args[2:]
match command:
case "add":
GymRepository.add(flags)
case "branch":
branch_args = branch_parser.parse_args()
GymRepository.branch(branch_args)
case "checkout":
checkout_args = checkout_parser.parse_args()
GymRepository.checkout(checkout_args)
case "commit":
commit_args = commit_parser.parse_args()
GymRepository.commit(commit_args)
case "init":
GymRepository.init(flags)
case "merge":
merge_args = merge_parser.parse_args()
GymRepository.merge(merge_args)
case "tag":
tag_args = tag_parser.parse_args()
GymRepository.tag(tag_args)
if __name__ == "__main__":
try:
main(sys.argv)
except GymException as e:
print(e)