@Test(expected=IllegalArgumentException.class) public void unsupportedOption() { SshCommand.parse("ssh -X jump1.example.com nc %h %p"); }
static public SshCommand parse(String value) { Deque<String> tokens = new ArrayDeque<>(Arrays.asList(value.split("\\s+"))); String executable = tokens.pop(); if (!Objects.equals(executable, "ssh")) { throw new IllegalArgumentException("Unable to parse command for executable '" + executable + "' (only support ssh)"); } SshCommand cmd = new SshCommand(); while (!tokens.isEmpty()) { String maybeArg = tokens.pop(); for (String arg : normalizeSwitch(maybeArg)) { switch (arg) { case "-F": cmd.configFile = tokens.pop(); break; case "-i": cmd.identityFile = tokens.pop(); break; case "-p": cmd.port = Integer.valueOf(tokens.pop()); break; case "-l": cmd.loginName = tokens.pop(); break; case "-W": cmd.fwdHostPort = tokens.pop(); break; case "-q": cmd.quiet = Boolean.TRUE; break; case "-A": cmd.forwardAgent = Boolean.TRUE; break; case "-a": cmd.forwardAgent = Boolean.FALSE; break; case "-4": cmd.ipAddrMode = 4; break; case "-6": cmd.ipAddrMode = 6; break; default: if (arg.startsWith("-")) { throw new IllegalArgumentException("Unsupported ssh switch [" + arg + "]"); } else { if (cmd.target == null) { cmd.target = arg; } else { if (cmd.commands == null) { cmd.commands = new ArrayList<>(); } cmd.commands.add(arg); } } break; } } } if (cmd.target == null) { throw new IllegalArgumentException("ssh command requires at least [user@]hostname"); } return cmd; }
SshCommand { static public SshCommand parse(String value) { Deque<String> tokens = new ArrayDeque<>(Arrays.asList(value.split("\\s+"))); String executable = tokens.pop(); if (!Objects.equals(executable, "ssh")) { throw new IllegalArgumentException("Unable to parse command for executable '" + executable + "' (only support ssh)"); } SshCommand cmd = new SshCommand(); while (!tokens.isEmpty()) { String maybeArg = tokens.pop(); for (String arg : normalizeSwitch(maybeArg)) { switch (arg) { case "-F": cmd.configFile = tokens.pop(); break; case "-i": cmd.identityFile = tokens.pop(); break; case "-p": cmd.port = Integer.valueOf(tokens.pop()); break; case "-l": cmd.loginName = tokens.pop(); break; case "-W": cmd.fwdHostPort = tokens.pop(); break; case "-q": cmd.quiet = Boolean.TRUE; break; case "-A": cmd.forwardAgent = Boolean.TRUE; break; case "-a": cmd.forwardAgent = Boolean.FALSE; break; case "-4": cmd.ipAddrMode = 4; break; case "-6": cmd.ipAddrMode = 6; break; default: if (arg.startsWith("-")) { throw new IllegalArgumentException("Unsupported ssh switch [" + arg + "]"); } else { if (cmd.target == null) { cmd.target = arg; } else { if (cmd.commands == null) { cmd.commands = new ArrayList<>(); } cmd.commands.add(arg); } } break; } } } if (cmd.target == null) { throw new IllegalArgumentException("ssh command requires at least [user@]hostname"); } return cmd; } }
SshCommand { static public SshCommand parse(String value) { Deque<String> tokens = new ArrayDeque<>(Arrays.asList(value.split("\\s+"))); String executable = tokens.pop(); if (!Objects.equals(executable, "ssh")) { throw new IllegalArgumentException("Unable to parse command for executable '" + executable + "' (only support ssh)"); } SshCommand cmd = new SshCommand(); while (!tokens.isEmpty()) { String maybeArg = tokens.pop(); for (String arg : normalizeSwitch(maybeArg)) { switch (arg) { case "-F": cmd.configFile = tokens.pop(); break; case "-i": cmd.identityFile = tokens.pop(); break; case "-p": cmd.port = Integer.valueOf(tokens.pop()); break; case "-l": cmd.loginName = tokens.pop(); break; case "-W": cmd.fwdHostPort = tokens.pop(); break; case "-q": cmd.quiet = Boolean.TRUE; break; case "-A": cmd.forwardAgent = Boolean.TRUE; break; case "-a": cmd.forwardAgent = Boolean.FALSE; break; case "-4": cmd.ipAddrMode = 4; break; case "-6": cmd.ipAddrMode = 6; break; default: if (arg.startsWith("-")) { throw new IllegalArgumentException("Unsupported ssh switch [" + arg + "]"); } else { if (cmd.target == null) { cmd.target = arg; } else { if (cmd.commands == null) { cmd.commands = new ArrayList<>(); } cmd.commands.add(arg); } } break; } } } if (cmd.target == null) { throw new IllegalArgumentException("ssh command requires at least [user@]hostname"); } return cmd; } SshCommand(); }
SshCommand { static public SshCommand parse(String value) { Deque<String> tokens = new ArrayDeque<>(Arrays.asList(value.split("\\s+"))); String executable = tokens.pop(); if (!Objects.equals(executable, "ssh")) { throw new IllegalArgumentException("Unable to parse command for executable '" + executable + "' (only support ssh)"); } SshCommand cmd = new SshCommand(); while (!tokens.isEmpty()) { String maybeArg = tokens.pop(); for (String arg : normalizeSwitch(maybeArg)) { switch (arg) { case "-F": cmd.configFile = tokens.pop(); break; case "-i": cmd.identityFile = tokens.pop(); break; case "-p": cmd.port = Integer.valueOf(tokens.pop()); break; case "-l": cmd.loginName = tokens.pop(); break; case "-W": cmd.fwdHostPort = tokens.pop(); break; case "-q": cmd.quiet = Boolean.TRUE; break; case "-A": cmd.forwardAgent = Boolean.TRUE; break; case "-a": cmd.forwardAgent = Boolean.FALSE; break; case "-4": cmd.ipAddrMode = 4; break; case "-6": cmd.ipAddrMode = 6; break; default: if (arg.startsWith("-")) { throw new IllegalArgumentException("Unsupported ssh switch [" + arg + "]"); } else { if (cmd.target == null) { cmd.target = arg; } else { if (cmd.commands == null) { cmd.commands = new ArrayList<>(); } cmd.commands.add(arg); } } break; } } } if (cmd.target == null) { throw new IllegalArgumentException("ssh command requires at least [user@]hostname"); } return cmd; } SshCommand(); Boolean getForwardAgent(); void setForwardAgent(Boolean forwardAgent); Integer getIpAddrMode(); void setIpAddrMode(Integer ipAddrMode); Boolean getQuiet(); void setQuiet(Boolean quiet); String getConfigFile(); void setConfigFile(String configFile); String getIdentityFile(); void setIdentityFile(String identityFile); Integer getPort(); void setPort(Integer port); String getLoginName(); void setLoginName(String loginName); String getFwdHostPort(); void setFwdHostPort(String fwdHostPort); String getTarget(); void setTarget(String target); List<String> getCommands(); void setCommands(List<String> commands); MutableUri toUri(); String toCommand(); void apply(SshConnect connect); static SshCommand parse(String value); }
SshCommand { static public SshCommand parse(String value) { Deque<String> tokens = new ArrayDeque<>(Arrays.asList(value.split("\\s+"))); String executable = tokens.pop(); if (!Objects.equals(executable, "ssh")) { throw new IllegalArgumentException("Unable to parse command for executable '" + executable + "' (only support ssh)"); } SshCommand cmd = new SshCommand(); while (!tokens.isEmpty()) { String maybeArg = tokens.pop(); for (String arg : normalizeSwitch(maybeArg)) { switch (arg) { case "-F": cmd.configFile = tokens.pop(); break; case "-i": cmd.identityFile = tokens.pop(); break; case "-p": cmd.port = Integer.valueOf(tokens.pop()); break; case "-l": cmd.loginName = tokens.pop(); break; case "-W": cmd.fwdHostPort = tokens.pop(); break; case "-q": cmd.quiet = Boolean.TRUE; break; case "-A": cmd.forwardAgent = Boolean.TRUE; break; case "-a": cmd.forwardAgent = Boolean.FALSE; break; case "-4": cmd.ipAddrMode = 4; break; case "-6": cmd.ipAddrMode = 6; break; default: if (arg.startsWith("-")) { throw new IllegalArgumentException("Unsupported ssh switch [" + arg + "]"); } else { if (cmd.target == null) { cmd.target = arg; } else { if (cmd.commands == null) { cmd.commands = new ArrayList<>(); } cmd.commands.add(arg); } } break; } } } if (cmd.target == null) { throw new IllegalArgumentException("ssh command requires at least [user@]hostname"); } return cmd; } SshCommand(); Boolean getForwardAgent(); void setForwardAgent(Boolean forwardAgent); Integer getIpAddrMode(); void setIpAddrMode(Integer ipAddrMode); Boolean getQuiet(); void setQuiet(Boolean quiet); String getConfigFile(); void setConfigFile(String configFile); String getIdentityFile(); void setIdentityFile(String identityFile); Integer getPort(); void setPort(Integer port); String getLoginName(); void setLoginName(String loginName); String getFwdHostPort(); void setFwdHostPort(String fwdHostPort); String getTarget(); void setTarget(String target); List<String> getCommands(); void setCommands(List<String> commands); MutableUri toUri(); String toCommand(); void apply(SshConnect connect); static SshCommand parse(String value);  }