cmd: fix to show exceptions if any

This commit is contained in:
Oleksii Shevchuk 2018-10-06 19:26:53 +03:00
parent 822bcdb013
commit 15fcd63948
1 changed files with 23 additions and 11 deletions

View File

@ -422,11 +422,20 @@ class PupyCmd(cmd.Cmd):
self.init_completer() self.init_completer()
def cmdloop(self, intro=None): def cmdloop(self, intro=None):
closed = False
while not closed:
try: try:
cmd.Cmd.cmdloop(self, intro) cmd.Cmd.cmdloop(self, intro)
except: closed = True
except KeyboardInterrupt:
self.stdout.write('\n') self.stdout.write('\n')
self.cmdloop(intro="")
except:
msg = hint_to_text(Error(traceback.format_exc()))
self.redraw_line(msg)
intro = ''
def init_completer(self): def init_completer(self):
readline.set_pre_input_hook(self.pre_input_hook) readline.set_pre_input_hook(self.pre_input_hook)
@ -529,12 +538,7 @@ class PupyCmd(cmd.Cmd):
text += '\n' text += '\n'
return self.stdout.write(text) return self.stdout.write(text)
def display_srvinfo(self, msg): def redraw_line(self, msg=''):
if isinstance(msg, Text):
msg = hint_to_text(msg)
else:
msg = colorize('[*] ', 'blue') + msg
buf = readline.get_line_buffer() buf = readline.get_line_buffer()
self.stdout.write(''.join([ self.stdout.write(''.join([
@ -550,6 +554,14 @@ class PupyCmd(cmd.Cmd):
except Exception: except Exception:
pass pass
def display_srvinfo(self, msg):
if isinstance(msg, Text):
msg = hint_to_text(msg)
else:
msg = colorize('[*] ', 'blue') + msg
self.redraw_line(msg)
def display_success(self, msg): def display_success(self, msg):
return self.display(Success(msg)) return self.display(Success(msg))