-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseCommands.py
58 lines (43 loc) · 1.55 KB
/
parseCommands.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
from commands import COMMAND_LIST_NO_ARGS, COMMAND_LIST_ONE_ARG, COMMAND_LIST_TWO_ARGS
from termcolor import colored
def showHelpMessage(key, value):
print("---")
print(f"Name: {key}\nDescription: {value.description}\n{value.usage}")
print("---")
def commandErrorMessage(command):
print(colored(f"mash: Command \"{command}\" not found", "red"))
def parseCommands(line: str, debug=False, shellName='powershell'):
keywords = line.split(' ')
command = keywords[0].lower()
if line.strip() == 'help' or line.strip() == '?':
print("------ INFO -----")
for key, value in COMMAND_LIST_NO_ARGS.items():
showHelpMessage(key, value)
for key, value in COMMAND_LIST_ONE_ARG.items():
showHelpMessage(key, value)
return
if line.strip() == '':
return
if debug:
print(keywords)
if len(keywords) == 1:
try:
COMMAND_LIST_NO_ARGS[command].use()
except KeyError:
commandErrorMessage(command)
except:
print(colored("Error Occured", "red"))
elif len(keywords) == 2:
arg = keywords[1]
try:
COMMAND_LIST_ONE_ARG[command].use(arg)
except KeyError:
commandErrorMessage(command)
elif len(keywords) == 3:
args = keywords[1:]
try:
COMMAND_LIST_TWO_ARGS[command].use(*args)
except KeyError:
commandErrorMessage(command)
else:
commandErrorMessage(command)