示例#1
0
 def _check_cmd(self):
     parser = get_command_parser(self.cmd)
     parser.add_option(
         "-d",
         "--here",
         dest="here",
         help="Set the directory or url that a command should run from. "
         "This affects all default path lookups but does not affect paths "
         "supplied to the command.",
         default=os.getcwd(),
         type=str)
     parser.add_option(
         "-q",
         "--quiet",
         action="store_true",
         default=False,
         help="Turn off output other than the primary output for a command "
         "and any errors.")
     # yank out --, as optparse makes it silly hard to just preserve it.
     try:
         where_dashdash = self._argv.index('--')
         opt_argv = self._argv[:where_dashdash]
         other_args = self._argv[where_dashdash:]
     except ValueError:
         opt_argv = self._argv
         other_args = []
     if '-h' in opt_argv or '--help' in opt_argv or '-?' in opt_argv:
         self.output_rest(parser.format_help())
         # Fugly, but its what optparse does: we're just overriding the
         # output path.
         raise SystemExit(0)
     options, args = parser.parse_args(opt_argv)
     args += other_args
     self.here = options.here
     self.options = options
     parsed_args = {}
     failed = False
     for arg in self.cmd.args:
         try:
             parsed_args[arg.name] = arg.parse(args)
         except ValueError:
             exc_info = sys.exc_info()
             failed = True
             self._stderr.write(_u("%s\n") % str(exc_info[1]))
             break
     if not failed:
         self.arguments = parsed_args
         if args != []:
             self._stderr.write(_u("Unexpected arguments: %r\n") % args)
     return not failed and args == []
示例#2
0
    def run(self):
        if not self.ui.arguments["command_name"]:
            version = ".".join(map(str, testrepository.__version__))
            help = (
                """testr %s -- a free test repository
https://launchpad.net/testrepository/

testr commands -- list commands
testr quickstart -- starter documentation
testr help [command] -- help system
"""
                % version
            )
        else:
            cmd = self.ui.arguments["command_name"][0]
            parser = get_command_parser(cmd)
            help = parser.format_help()
        self.ui.output_rest(help)
        return 0
示例#3
0
 def _check_cmd(self):
     parser = get_command_parser(self.cmd)
     parser.add_option("-d", "--here", dest="here",
         help="Set the directory or url that a command should run from. "
         "This affects all default path lookups but does not affect paths "
         "supplied to the command.", default=os.getcwd(), type=str)
     parser.add_option("-q", "--quiet", action="store_true", default=False,
         help="Turn off output other than the primary output for a command "
         "and any errors.")
     # yank out --, as optparse makes it silly hard to just preserve it.
     try:
         where_dashdash = self._argv.index('--')
         opt_argv = self._argv[:where_dashdash]
         other_args = self._argv[where_dashdash:]
     except ValueError:
         opt_argv = self._argv
         other_args = []
     if '-h' in opt_argv or '--help' in opt_argv or '-?' in opt_argv:
         self.output_rest(parser.format_help())
         # Fugly, but its what optparse does: we're just overriding the
         # output path.
         raise SystemExit(0)
     options, args = parser.parse_args(opt_argv)
     args += other_args
     self.here = options.here
     self.options = options
     parsed_args = {}
     failed = False
     for arg in self.cmd.args:
         try:
             parsed_args[arg.name] = arg.parse(args)
         except ValueError:
             exc_info = sys.exc_info()
             failed = True
             self._stderr.write(_u("%s\n") % str(exc_info[1]))
             break
     if not failed:
         self.arguments = parsed_args
         if args != []:
             self._stderr.write(_u("Unexpected arguments: %r\n") % args)
     return not failed and args == []
 def test_trivial(self):
     cmd = InstrumentedCommand(model.UI())
     parser = commands.get_command_parser(cmd)
     self.assertThat(parser, IsInstance(optparse.OptionParser))
示例#5
0
 def test_trivial(self):
     cmd = InstrumentedCommand(model.UI())
     parser = commands.get_command_parser(cmd)
     self.assertThat(parser, IsInstance(optparse.OptionParser))