def error(self, message): import sys as _sys # dirty hack - only top level binary has suppressed usage if self.usage == argparse.SUPPRESS: wants_help = '-h' in _sys.argv or '--help' in _sys.argv if not wants_help: print('Couldn\'t parse input, displaying help ...\n') print(HelpAction.get_help()) if wants_help: self.exit(0) else: self.exit(1) else: # python 2 and 3 hooks to grab missing subassistant argument and report it meaningfully if message == _( 'too few arguments' ) or settings.SUBASSISTANT_N_STRING[:-3] in message: for action in self._get_positional_actions(): if isinstance(action, argparse._SubParsersAction): if message == _('too few arguments') and len( action.choices) == 0: self.exit(2, _('No subassistants available.\n')) else: self.print_usage(_sys.stderr) self.exit( 2, _('You have to select a subassistant.\n')) self.print_usage(_sys.stderr) self.exit(1, _('%s: error: %s\n') % (self.prog, message))
def error(self, message): # dirty hack - only top level binary has suppressed usage if self.usage == argparse.SUPPRESS: wants_help = '-h' in sys.argv or '--help' in sys.argv if not wants_help: print('Couldn\'t parse input, displaying help ...\n') print(HelpAction.get_help()) if wants_help: self.exit(0) else: self.exit(1) else: if message == _('too few arguments') or settings.SUBASSISTANT_N_STRING[:-3] in message: self._bad_subassistant_error(message) self.print_usage(sys.stderr) self.exit(1, _('%s: error: %s\n') % (self.prog, message))
def error(self, message): import sys as _sys # dirty hack - only top level binary has suppressed usage if self.usage == argparse.SUPPRESS: wants_help = '-h' in _sys.argv or '--help' in _sys.argv if not wants_help: print('Couldn\'t parse input, displaying help ...\n') print(HelpAction.get_help()) if wants_help: self.exit(0) else: self.exit(1) else: self.print_usage(_sys.stderr) # python 2 and 3 hooks to grab missing subassistant argument and report it meaningfully if message == _('too few arguments') or settings.SUBASSISTANT_N_STRING[:-3] in message: for action in self._get_positional_actions(): if isinstance(action, argparse._SubParsersAction): self.exit(2, _('You have to select a subassistant.\n')) self.exit(1, _('%s: error: %s\n') % (self.prog, message))
def error(self, message): import sys as _sys # dirty hack - only top level binary has suppressed usage if self.usage == argparse.SUPPRESS: wants_help = '-h' in _sys.argv or '--help' in _sys.argv if not wants_help: print('Couldn\'t parse input, displaying help ...\n') print(HelpAction.get_help()) if wants_help: self.exit(0) else: self.exit(1) else: # python 2 and 3 hooks to grab missing subassistant argument and report it meaningfully if message == _('too few arguments') or settings.SUBASSISTANT_N_STRING[:-3] in message: for action in self._get_positional_actions(): if isinstance(action, argparse._SubParsersAction): if message == _('too few arguments') and len(action.choices) == 0: msg = ['No subassistants available.', '', 'To search DevAssistant Package Index (DAPI) for new assistants,', 'you can either browse https://dapi.devassistant.org/ or run', '', '"da pkg search <term>".', '', 'Then you can run', '', '"da pkg install <DAP-name>"', '', 'to install the desired DevAssistant package (DAP).\n'] self.exit(2, _('\n'.join(msg))) else: self.print_usage(_sys.stderr) prog = getattr(action, '_prog_prefix', 'crt').split()[0] if prog in settings.ASSISTANT_ROLES: self.exit(2, _('You have to select a subassistant.\n')) else: self.exit(2, _('You have to select a subaction.\n')) self.print_usage(_sys.stderr) self.exit(1, _('%s: error: %s\n') % (self.prog, message))