blob: e67c853711520c465e89a1e0bcd7cc3fb2f7e419 (
plain)
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
|
#!/usr/bin/python3
import signal, sys
from lib.outputmanager import OutputManager
from lib.commandmanager import CommandManager
from lib.completionmanager import CompletionManager
from lib.exceptions import CmdNotFoundException, CommandException
class Manager:
def __init__(self):
self.loader = None
self.completer = CompletionManager(cmd_manager, self.loader)
def start(self):
try:
signal.signal(signal.SIGINT, signal.default_int_handler)
while True:
try:
try:
line = input('% ')
except KeyboardInterrupt:
output_manager.line_break()
continue
cmd_name = line.strip().split(' ')
if len(cmd_name) > 0 and len(cmd_name[0]) > 0:
cmd = cmd_manager.find(cmd_name[0])
cmd.execute(self.loader, line[1:] if len(line) > 1 else [])
except CommandException as err:
output_manager.error(str(err)).linebreak()
if err.print_usage:
output_manager.normal('Usage: {0}'.format(cmd.usage(line[0]))).line_break()
except CmdNotFoundException as err:
output_manager.error('Error: {0}'.format(str(err))).line_break()
except EOFError:
output_manager.line_break()
exit(0)
except:
raise
if __name__ == '__main__':
try:
cmd_manager = CommandManager()
manager = Manager()
output_manager = OutputManager()
manager.start()
except: # TODO: Improve exceptions handling
print("Unexpected error:", sys.exc_info()[0])
raise
|