if (args.length<2) {
System.out.println("No arguments specified!\n");
throw new InvalidParameterException("No arguments specified!");
}
CmdLineParser parser = new CmdLineParser();
CmdLineParser.Option host = parser.addStringOption('h', PARAM_HOST);
CmdLineParser.Option port = parser.addIntegerOption('p', PARAM_PORT);
CmdLineParser.Option command = parser.addStringOption('c', PARAM_COMMAND);
String pCmd = "undefined";
try {
parser.parse(args);
String pHost = (String)parser.getOptionValue(host, DEFAULT_HOST);
int pPort = (Integer)parser.getOptionValue(port, DEFAULT_PORT);
pCmd = (String)parser.getOptionValue(command);
if (pCmd==null) {
System.out.println("Unknown Command: "+ArrayUtils.toString(args));
System.out.println("Exit now");
throw new IllegalArgumentException("no ValidCommand specified!");
}
ValidCommands parsedCommand = ValidCommands.valueOf(pCmd.toUpperCase());
String[] otherArgs = parser.getRemainingArgs();
if (parsedCommand.getNrOfParams() < otherArgs.length) {
String err = "Invalid parameter count, expected: "+parsedCommand.getNrOfParams()+", provided: "+otherArgs.length;
System.out.println(err);
throw new InvalidParameterException(err);