Пример #1
0
def run_argv(argv, stdin, stdout, stderr):
    """Convenience function to run a command with a CLIUI.

    :param argv: The argv to run the command with.
    :param stdin: The stdin stream for the command.
    :param stdout: The stdout stream for the command.
    :param stderr: The stderr stream for the command.
    :return: An integer exit code for the command.
    """
    cmd_name = None
    cmd_args = argv[1:]
    for arg in argv[1:]:
        if not arg.startswith('-'):
            cmd_name = arg
            break
    if cmd_name is None:
        cmd_name = 'help'
        cmd_args = ['help']
    cmd_args.remove(cmd_name)
    cmdclass = commands._find_command(cmd_name)
    ui = UI(cmd_args, stdin, stdout, stderr)
    cmd = cmdclass(ui)
    result = cmd.execute()
    if not result:
        return 0
    return result
Пример #2
0
 def test_sets_name(self):
     cmd = commands._find_command('foo')
     self.assertEqual('foo', cmd.name)
Пример #3
0
 def test_looksupcommand_hypen(self):
     cmd = commands._find_command('foo-bar')
     self.assertIsInstance(cmd(None), commands.Command)
Пример #4
0
 def _parse_one(self, arg):
     try:
         return commands._find_command(arg)
     except KeyError:
         raise CustomError("Could not find command '%s'." % arg)