void parseCommandLine(String[] args) { // @formatter:on CommandLineParser parser = new DefaultParser(); try { commandline = parser.parse(options, args); } catch (AlreadySelectedException ase) { help(CliBase.InvalidCommandLine, "Already Selected: " + ase.getOption()); } catch (AmbiguousOptionException aoe) { help(CliBase.InvalidCommandLine, "Ambiguous Option: " + aoe.getMatchingOptions()); } catch (MissingArgumentException mae) { help(CliBase.InvalidCommandLine, "Missing Argument: " + mae.getOption()); } catch (MissingOptionException moe) { help(CliBase.InvalidCommandLine, "Missing Option: " + moe.getMissingOptions()); } catch (UnrecognizedOptionException uoe) { help(CliBase.InvalidCommandLine, "Unrecongnized Option: " + uoe.getOption()); } catch (Exception e) { help(CliBase.InvalidCommandLine, "Unexpected Exception: " + e.getClass().getName()); } if (commandline.hasOption(CliBase.HelpShortCl)) help(0, null); if (commandline.hasOption(CliBase.VersionShortCl)) cliBase.version(); }
public static void main(String args[]) throws Exception { options.addOption("h", "help", false, "Display the help."); options.addOption("v", "verbose", false, "Display more messages."); options.addOption("f", "file", true, "Image or directory to analyse."); options.addOption("d", "debug", false, "Enable debug mode."); options.addOption("e", "exif", false, "Turns on exif analysis."); options.addOption("rd", "race-data", false, "Turns on race data analysis."); File file = null; File fileToAnalyse = null; CommandLineParser parser = new DefaultParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption("h")) { usage(); System.exit(0); } if (line.hasOption("v")) { verboseIsEnabled = true; } if (line.hasOption("f")) { file = new File(line.getOptionValue("f")); } if (line.hasOption("d")) { debugIsEnabled = true; } if (line.hasOption("e")) { exifIsEnabled = true; } if (line.hasOption("rd")) { raceDataIsEnabled = true; fileToAnalyse = new File(line.getOptionValue("rd")); } } catch (MissingArgumentException e) { System.err.println("Option <" + e.getOption().getOpt() + "> need an argument!"); usage(); System.exit(1); } catch (ParseException e) { System.out.println("Unexpected exception: " + e.getMessage()); } if (file == null) { System.err.println("Please specify a file or a directory with option <f>."); usage(); System.exit(1); } processingController.setProcessSettings(exifIsEnabled, raceDataIsEnabled, debugIsEnabled); UUID plID = processingController.acknowledge(file); processingController.processing(plID); if (raceDataIsEnabled) { photoListCtrl.addRaceData(plID, fileToAnalyse); photoListCtrl.processAdditionalData(plID); } if (file.isFile()) { System.out.println( processingController .loadedPhotoLists .get(processingController.getPlidFromImgid(plID)) .toJSON()); } else { System.out.println(ProcessingCtrl.loadedPhotoLists.get(plID).toJSON()); } }