File size: 1,207 Bytes
6309782
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys
from beta.shellLogic import simpleParser
from mainLogic.utils.os2 import SysFunc

os2 = SysFunc()


class HandleBasicCMDUtils:
    # basic class for handling basic commands
    # every such class must have a method to parse command (regex based) a help for each command handled by the class

    def __init__(self):
        self.commandList = {
            "cls":
                {
                    "desc": "Clear the screen",
                    "regex": r"cls",
                    "func": self.cls
                },
            "exit":
                {
                    "desc": "Exit the shell",
                    "regex": r"exit",
                    "func": self.exit_shell
                },
        }

    def cls(self,args=[]):
        os2.clear()
        if args: print(args)

    def exit_shell(self,args=[]):
        sys.exit(10)

    def parseAndRun(self, command,args=[]):
        # for key in self.commandList:
        #     if re.match(self.commandList[key]["regex"], command):
        #         self.commandList[key]["func"]()
        #         return
        # raise logicError.commandNotFound(command)
        simpleParser.parseAndRun(self.commandList, command, args)