comparison frontends/src/jp/base.py @ 2213:1010054cf771

jp (base): added msg and exit_code argument to errback so it's more generic
author Goffi <goffi@goffi.org>
date Wed, 29 Mar 2017 19:42:44 +0200
parents 33b82250eadd
children 4db836386641
comparison
equal deleted inserted replaced
2212:eaf2467d19ce 2213:1010054cf771
757 output_type = self._output_type 757 output_type = self._output_type
758 except AttributeError: 758 except AttributeError:
759 raise exceptions.InternalError(_(u'trying to use output when use_output has not been set')) 759 raise exceptions.InternalError(_(u'trying to use output when use_output has not been set'))
760 return self.host.output(output_type, self.args.output, self.extra_outputs, data) 760 return self.host.output(output_type, self.args.output, self.extra_outputs, data)
761 761
762 def errback(self, failure_): 762 def errback(self, failure_, msg=None, exit_code=C.EXIT_ERROR):
763 """generic callback for errbacks 763 """generic callback for errbacks
764 764
765 display failure_ then quit with generic error 765 display failure_ then quit with generic error
766 @param failure_: arguments returned by errback 766 @param failure_: arguments returned by errback
767 """ 767 @param msg(unicode, None): message template
768 self.disp(u"error: {}".format(failure_), error=True) 768 use {} if you want to display failure message
769 self.host.quit(C.EXIT_ERROR) 769 @param exit_code(int): shell exit code
770 """
771 if msg is None:
772 msg = _(u"error: {}")
773 self.disp(msg.format(failure_), error=True)
774 self.host.quit(exit_code)
770 775
771 def add_parser_options(self): 776 def add_parser_options(self):
772 try: 777 try:
773 subcommands = self.subcommands 778 subcommands = self.subcommands
774 except AttributeError: 779 except AttributeError: