For some reason, the Apache CLI package will not read more than one command from the command line
If I give this command:
java -cp FTPCleanup.jar com.echostar.ittools.FTPCleanup -loggerconfig logger.development.properties -ftpconfig ftpcleanup.development.properties
If gives this error:
Parsing the command line failed. Reason: -ftpconfig
Now if I reverse the options on the command line, then the error will be on the "loggerconfig" argument. How can I get both options to be read in? The documentation is giving me a headache while trying to understand what I am doing wrong.
The code is below.
Option ftpconfig = OptionBuilder.withArgName( "ftpconfig").hasArg().isRequired().withDescription("Path to the FTPCleanup properties file").create("ftpconfig");
Option loggerconfig = OptionBuilder.withArgName( "loggerconfig").hasArg().isRequired().withDescription("Path to the logger properties file").create("loggerconfig");
options.addOption( ftpconfig );
options.addOption( loggerconfig );
CommandLineParser parser = new BasicParser();
org.apache.commons.cli.CommandLine line = null;
// CommandLineParser parser = new GnuParser();
try {
line = parser.parse(options, args);
if ( line.hasOption( "ftpconfig" ) ) {
System.out.println("ftpconfig is " + line.getOptionValue("ftpconfig"));
}
else {
System.out.println("ftpconfig not defined.");
}
if ( line.hasOption( "loggerconfig" ) ) {
System.out.println("loggerconfig is " + line.getOptionValue("loggerconfig") );
}
else {
System.out.println("loggerconfig not defined.");
}
}
catch( org.apache.commons.cli.ParseException exp ) {
System.err.println( "Parsing the command line failed. Reason: " + exp.getMessage() );
return false;
}
}