-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbase.py
More file actions
47 lines (36 loc) · 1.26 KB
/
Copy pathbase.py
File metadata and controls
47 lines (36 loc) · 1.26 KB
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
"""Base class for command line interface. It acts as the brain. It compares
the first argument of the command and matches it with the given COMMANDS.
Then it calls the respective class to do the work.
"""
import sys
COMMANDS = ['cat', 'sort', 'search', 'list', 'bye']
class base:
def __init__(self, expr):
self.expr = expr.split(' ')
def check_command(self):
if self.expr[0] in COMMANDS:
return True
else:
return False
def do(self):
if self.check_command() == False:
print ('Command not found')
return '\n'
if self.expr[0] == 'sort':
from core.sort import sort
action = sort(self.expr)
print(action.parse())
elif self.expr[0] == 'cat':
from core.cat import cat
action = cat(self.expr)
print(action.parse())
elif self.expr[0] == 'search':
from core.search import search
action = search(self.expr)
print(action.parse())
elif self.expr[0] == 'list':
from core.listall import list_all
action = list_all(self.expr)
print(action.parse())
elif self.expr[0] == 'bye':
sys.exit()