def passthrough(options, extra): """Second parsing phase to parse `extra` to passthrough to scp itself. Partitions into flags and file specifications. """ flags, positional = parse_passthrough_args(extra, "cFiloPS") if not positional: raise ParseError("too few arguments") options.scp_flags = flags options.paths = positional
def passthrough(options, extra): """Second parsing phase to parse `extra` to passthrough to ssh itself. Partitions into flags, unit_or_machine, and optional ssh command. """ flags, positional = parse_passthrough_args(extra, "bcDeFIiLlmOopRSWw") if not positional: raise ParseError("too few arguments") options.ssh_flags = flags options.unit_or_machine = positional.pop(0) options.ssh_command = positional # if any
def test_parse_typical_ssh(self): """Verify that flags and positional args are properly partitioned.""" ssh_flags = "bcDeFIiLlmOopRSWw" self.assertEqual( parse_passthrough_args( ["-L8080:localhost:80", "-o", "Volume 11", "mysql/0", "ls a*"], ssh_flags), (["-L8080:localhost:80", "-o", "Volume 11"], ["mysql/0", "ls a*"])) self.assertEqual( parse_passthrough_args( ["-L8080:localhost:80", "-aC26", "0", "foobar", "do", "123"], ssh_flags), (["-L8080:localhost:80", "-aC26"], ["0", "foobar", "do", "123"])) self.assertEqual( parse_passthrough_args(["mysql/0"], ssh_flags), ([], ["mysql/0"])) self.assertEqual( parse_passthrough_args( ["mysql/0", "command", "-L8080:localhost:80"], ssh_flags), ([], ["mysql/0", "command", "-L8080:localhost:80"]))
def test_parse_flag_taking_args(self): """Verify that arg-taking flags properly combine with args""" # some sample flags, from the ssh command ssh_flags = "bcDeFIiLlmOopRSWw" for flag in ssh_flags: # This flag properly combines, either of the form -Xabc or -X abc self.assertEqual( parse_passthrough_args( ["-" + flag + "XYZ", "-1X", "-" + flag, "XYZ", "mysql/0"], ssh_flags), (["-" + flag + "XYZ", "-1X", "-" + flag, "XYZ"], ["mysql/0"])) # And requires that it is combined e = self.assertRaises( ParseError, parse_passthrough_args, ["-" + flag], ssh_flags) self.assertEqual(str(e), "argument -%s: expected one argument" % flag)