@Test public void testValidate() { assertTrue(new TerminalOptionsInputValidator(new ProtocolFactory(Collections.singleton(new FTPProtocol() { @Override public boolean isEnabled() { return true; } }))) .validate("ftp: assertTrue(new TerminalOptionsInputValidator(new ProtocolFactory(Collections.singleton(new FTPProtocol() { @Override public boolean isEnabled() { return true; } }))) .validate("ftp: }
public boolean validate(final CommandLine input) { for(Option o : input.getOptions()) { if(Option.UNINITIALIZED == o.getArgs()) { continue; } if(o.hasOptionalArg()) { continue; } if(o.getArgs() != o.getValuesList().size()) { console.printf("Missing argument for option %s%n", o.getLongOpt()); return false; } } final TerminalAction action = TerminalActionFinder.get(input); if(null == action) { console.printf("%s%n", "Missing argument"); return false; } if(input.hasOption(TerminalOptionsBuilder.Params.existing.name())) { final String arg = input.getOptionValue(TerminalOptionsBuilder.Params.existing.name()); if(null == TransferAction.forName(arg)) { final Set<TransferAction> actions = new HashSet<TransferAction>(TransferAction.forTransfer(Transfer.Type.download)); actions.add(TransferAction.cancel); console.printf("Invalid argument '%s' for option %s. Must be one of %s%n", arg, TerminalOptionsBuilder.Params.existing.name(), Arrays.toString(actions.toArray())); return false; } switch(action) { case download: if(!validate(arg, Transfer.Type.download)) { return false; } break; case upload: if(!validate(arg, Transfer.Type.upload)) { return false; } break; case synchronize: if(!validate(arg, Transfer.Type.sync)) { return false; } break; case copy: if(!validate(arg, Transfer.Type.copy)) { return false; } break; } } switch(action) { case list: case download: if(!validate(input.getOptionValue(action.name()))) { return false; } break; case upload: case copy: case synchronize: if(!validate(input.getOptionValue(action.name()))) { return false; } break; } return true; }
TerminalOptionsInputValidator { public boolean validate(final CommandLine input) { for(Option o : input.getOptions()) { if(Option.UNINITIALIZED == o.getArgs()) { continue; } if(o.hasOptionalArg()) { continue; } if(o.getArgs() != o.getValuesList().size()) { console.printf("Missing argument for option %s%n", o.getLongOpt()); return false; } } final TerminalAction action = TerminalActionFinder.get(input); if(null == action) { console.printf("%s%n", "Missing argument"); return false; } if(input.hasOption(TerminalOptionsBuilder.Params.existing.name())) { final String arg = input.getOptionValue(TerminalOptionsBuilder.Params.existing.name()); if(null == TransferAction.forName(arg)) { final Set<TransferAction> actions = new HashSet<TransferAction>(TransferAction.forTransfer(Transfer.Type.download)); actions.add(TransferAction.cancel); console.printf("Invalid argument '%s' for option %s. Must be one of %s%n", arg, TerminalOptionsBuilder.Params.existing.name(), Arrays.toString(actions.toArray())); return false; } switch(action) { case download: if(!validate(arg, Transfer.Type.download)) { return false; } break; case upload: if(!validate(arg, Transfer.Type.upload)) { return false; } break; case synchronize: if(!validate(arg, Transfer.Type.sync)) { return false; } break; case copy: if(!validate(arg, Transfer.Type.copy)) { return false; } break; } } switch(action) { case list: case download: if(!validate(input.getOptionValue(action.name()))) { return false; } break; case upload: case copy: case synchronize: if(!validate(input.getOptionValue(action.name()))) { return false; } break; } return true; } }
TerminalOptionsInputValidator { public boolean validate(final CommandLine input) { for(Option o : input.getOptions()) { if(Option.UNINITIALIZED == o.getArgs()) { continue; } if(o.hasOptionalArg()) { continue; } if(o.getArgs() != o.getValuesList().size()) { console.printf("Missing argument for option %s%n", o.getLongOpt()); return false; } } final TerminalAction action = TerminalActionFinder.get(input); if(null == action) { console.printf("%s%n", "Missing argument"); return false; } if(input.hasOption(TerminalOptionsBuilder.Params.existing.name())) { final String arg = input.getOptionValue(TerminalOptionsBuilder.Params.existing.name()); if(null == TransferAction.forName(arg)) { final Set<TransferAction> actions = new HashSet<TransferAction>(TransferAction.forTransfer(Transfer.Type.download)); actions.add(TransferAction.cancel); console.printf("Invalid argument '%s' for option %s. Must be one of %s%n", arg, TerminalOptionsBuilder.Params.existing.name(), Arrays.toString(actions.toArray())); return false; } switch(action) { case download: if(!validate(arg, Transfer.Type.download)) { return false; } break; case upload: if(!validate(arg, Transfer.Type.upload)) { return false; } break; case synchronize: if(!validate(arg, Transfer.Type.sync)) { return false; } break; case copy: if(!validate(arg, Transfer.Type.copy)) { return false; } break; } } switch(action) { case list: case download: if(!validate(input.getOptionValue(action.name()))) { return false; } break; case upload: case copy: case synchronize: if(!validate(input.getOptionValue(action.name()))) { return false; } break; } return true; } TerminalOptionsInputValidator();  TerminalOptionsInputValidator(final ProtocolFactory factory); }
TerminalOptionsInputValidator { public boolean validate(final CommandLine input) { for(Option o : input.getOptions()) { if(Option.UNINITIALIZED == o.getArgs()) { continue; } if(o.hasOptionalArg()) { continue; } if(o.getArgs() != o.getValuesList().size()) { console.printf("Missing argument for option %s%n", o.getLongOpt()); return false; } } final TerminalAction action = TerminalActionFinder.get(input); if(null == action) { console.printf("%s%n", "Missing argument"); return false; } if(input.hasOption(TerminalOptionsBuilder.Params.existing.name())) { final String arg = input.getOptionValue(TerminalOptionsBuilder.Params.existing.name()); if(null == TransferAction.forName(arg)) { final Set<TransferAction> actions = new HashSet<TransferAction>(TransferAction.forTransfer(Transfer.Type.download)); actions.add(TransferAction.cancel); console.printf("Invalid argument '%s' for option %s. Must be one of %s%n", arg, TerminalOptionsBuilder.Params.existing.name(), Arrays.toString(actions.toArray())); return false; } switch(action) { case download: if(!validate(arg, Transfer.Type.download)) { return false; } break; case upload: if(!validate(arg, Transfer.Type.upload)) { return false; } break; case synchronize: if(!validate(arg, Transfer.Type.sync)) { return false; } break; case copy: if(!validate(arg, Transfer.Type.copy)) { return false; } break; } } switch(action) { case list: case download: if(!validate(input.getOptionValue(action.name()))) { return false; } break; case upload: case copy: case synchronize: if(!validate(input.getOptionValue(action.name()))) { return false; } break; } return true; } TerminalOptionsInputValidator();  TerminalOptionsInputValidator(final ProtocolFactory factory); boolean validate(final CommandLine input); }
TerminalOptionsInputValidator { public boolean validate(final CommandLine input) { for(Option o : input.getOptions()) { if(Option.UNINITIALIZED == o.getArgs()) { continue; } if(o.hasOptionalArg()) { continue; } if(o.getArgs() != o.getValuesList().size()) { console.printf("Missing argument for option %s%n", o.getLongOpt()); return false; } } final TerminalAction action = TerminalActionFinder.get(input); if(null == action) { console.printf("%s%n", "Missing argument"); return false; } if(input.hasOption(TerminalOptionsBuilder.Params.existing.name())) { final String arg = input.getOptionValue(TerminalOptionsBuilder.Params.existing.name()); if(null == TransferAction.forName(arg)) { final Set<TransferAction> actions = new HashSet<TransferAction>(TransferAction.forTransfer(Transfer.Type.download)); actions.add(TransferAction.cancel); console.printf("Invalid argument '%s' for option %s. Must be one of %s%n", arg, TerminalOptionsBuilder.Params.existing.name(), Arrays.toString(actions.toArray())); return false; } switch(action) { case download: if(!validate(arg, Transfer.Type.download)) { return false; } break; case upload: if(!validate(arg, Transfer.Type.upload)) { return false; } break; case synchronize: if(!validate(arg, Transfer.Type.sync)) { return false; } break; case copy: if(!validate(arg, Transfer.Type.copy)) { return false; } break; } } switch(action) { case list: case download: if(!validate(input.getOptionValue(action.name()))) { return false; } break; case upload: case copy: case synchronize: if(!validate(input.getOptionValue(action.name()))) { return false; } break; } return true; } TerminalOptionsInputValidator();  TerminalOptionsInputValidator(final ProtocolFactory factory); boolean validate(final CommandLine input);  }