I get a correct result, but with the below error :
Error while parsing the command line: Unrecognized option: -f
public void run(String... args){
Options options = new Options();
options.addOption("h", "help", false, "prints the help content");
options.addOption("f", "fileType", true, "file type");
LoadReferenceFileRequest request=new LoadReferenceFileRequest();
try{
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parser.parse(options, args);
if(commandLine.hasOption("f") && commandLine.hasOption("u") && commandLine.hasOption("d")) {
String fileType = commandLine.getOptionValue("f");
request.setFileType(fileType);
String url = commandLine.getOptionValue("u");
request.setUrl(url);
String validDate = commandLine.getOptionValue("d");
request.setValidDate(validDate);
LoadReferenceFileResponse response= loadReferenceFileClientService.invoke(request);
System.out.println(response);
}else {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "Osmium Spa" , options );
System.exit(1);
}
}catch(MissingOptionException e){
//vérifie si l'option -h est présente
boolean help = false;
try{
Options helpOptions = new Options();
helpOptions.addOption("h", "help", false, "prints the help content");
CommandLineParser parser = new DefaultParser();
CommandLine line = parser.parse(helpOptions, args);
if(line.hasOption("h")) help = true;
}
catch(Exception ex){ }
if(!help) System.err.println(e.getMessage());
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "Osmium Spa" , options );
System.exit(1);
}
}
any help please, I would like to take off this error thanks in advance !!