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
def test_sets_name(self): cmd = commands._find_command('foo') self.assertEqual('foo', cmd.name)
def test_looksupcommand_hypen(self): cmd = commands._find_command('foo-bar') self.assertIsInstance(cmd(None), commands.Command)
def _parse_one(self, arg): try: return commands._find_command(arg) except KeyError: raise CustomError("Could not find command '%s'." % arg)