def run(self):
    """
      Run the multiopt parser
    """
    self.parser = MultioptOptionParser(
      usage="%prog <command> [options] [args]",
      prog=self.clsname,
      version=self.version,
      option_list=self.global_options,
      description=self.desc_short,
      commands=self.command_set,
      epilog=self.footer
    )
    
    try:
      self.options, self.args = self.parser.parse_args(self.argv)    
    except Exception, e:
      print str(e)
      pass

    if len(self.args) < 1:
      self.parser.print_lax_help()
      return 2
    
    self.command = self.args.pop(0)
    showHelp = False
    
    if self.command == 'help': 
      if len(self.args) < 1:
        self.parser.print_lax_help()
        return 2
      else:
        self.command = self.args.pop()
        showHelp = True

    if self.command not in self.valid_commands:
      self.parser.print_cmd_error(self.command)
      return 2

    self.command_set[self.command].set_cmdname(self.command)
    subcmd_parser = self.command_set[self.command].get_parser(self.clsname, self.version, self.global_options)
    subcmd_options, subcmd_args = subcmd_parser.parse_args(self.args)

    if showHelp:
      subcmd_parser.print_help_long()
      return 1

    try:
      self.command_set[self.command].func(subcmd_options, *subcmd_args)
    except (CommandError, TypeError), e:
      # self.parser.print_exec_error(self.command, str(e))
      subcmd_parser.print_exec_error(self.command, str(e))
      print 
      # @TODO show command help
      # self.parser.print_lax_help()
      return 2

      
    return 1
def run ( self ) : self . parser = MultioptOptionParser ( usage = "%prog <command> [options] [args]" , prog = self . clsname , version = self . version , option_list = self . global_options , description = self . desc_short , commands = self . command_set , epilog = self . footer ) try : self . options , self . args = self . parser . parse_args ( self . argv ) except Exception , e : print str ( e ) pass if len ( self . args ) < 1 : self . parser . print_lax_help ( ) return 2 self . command = self . args . pop ( 0 ) showHelp = False if self . command == 'help' : if len ( self . args ) < 1 : self . parser . print_lax_help ( ) return 2 else : self . command = self . args . pop ( ) showHelp = True if self . command not in self . valid_commands : self . parser . print_cmd_error ( self . command ) return 2 self . command_set [ self . command ] . set_cmdname ( self . command ) subcmd_parser = self . command_set [ self . command ] . get_parser ( self . clsname , self . version , self . global_options ) subcmd_options , subcmd_args = subcmd_parser . parse_args ( self . args ) if showHelp : subcmd_parser . print_help_long ( ) return 1 try : self . command_set [ self . command ] . func ( subcmd_options , * subcmd_args ) except ( CommandError , TypeError ) , e : subcmd_parser . print_exec_error ( self . command , str ( e ) ) print return 2 return 1
Run the multiopt parser