List of usage examples for org.apache.commons.cli Options Options
Options
From source file:de.peregrinus.autocopyreport.AutoCopyReport.java
public static void main(String[] args) { SongInfo si;/*from w ww. java 2s .co m*/ String openlpPath = ""; String crPath = ""; String crDataPath = ""; String crPassword = ""; System.out.println("AutoCopyReport v.1.00.00"); System.out.println("(c) 2014 Volksmission Freudenstadt"); System.out.println("Author: Christoph Fischer <christoph.fischer@volksmission.de>"); //System.out.println("Available under the General Public License (GPL) v2"); System.out.println(); // get options Options options = new Options(); options.addOption("h", "help", false, "display a list of available options"); options.addOption(OptionBuilder.withLongOpt("openlp-path").withDescription("path to OpenLP data directory") .hasArg().withArgName("PATH").create()); options.addOption(OptionBuilder.withLongOpt("copyreport-path") .withDescription("path to the CopyReport program directory").hasArg().withArgName("PATH").create()); options.addOption(OptionBuilder.withLongOpt("copyreport-data-path") .withDescription("path to the CopyReport data directory").hasArg().withArgName("PATH").create()); options.addOption(OptionBuilder.withLongOpt("password") .withDescription("internal password for the CopyReport database").hasArg().withArgName("PASSWORD") .create()); // parse command line try { // parse the command line arguments CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); // validate that block-size has been set if (line.hasOption("help")) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("AutoCopyReport", options); System.exit(0); } else { if (line.hasOption("openlp-path")) { openlpPath = line.getOptionValue("openlp-path") + "/songs/songs.sqlite"; System.out.println("OpenLP data path: " + openlpPath); } else { System.out.println( "ERROR: Please supply the path to your OpenLP data folder by using the --openlp-path parameter."); System.exit(0); } if (line.hasOption("copyreport-path")) { crPath = line.getOptionValue("copyreport-path"); System.out.println("Copyreport application database: " + crPath + "/ccldata.h2.db"); } else { System.out.println( "ERROR: Please supply the path to your CopyReport program folder by using the --copyreport-path parameter."); System.exit(0); } if (line.hasOption("copyreport-data-path")) { crDataPath = line.getOptionValue("copyreport-data-path"); System.out.println("Copyreport user database: " + crDataPath + "/userdata.h2.db"); } else { System.out.println( "ERROR: Please supply the path to your CopyReport data folder by using the --copyreport-data-path parameter."); System.exit(0); } if (line.hasOption("password")) { crPassword = line.getOptionValue("password"); } else { System.out.println( "ERROR: Please supply the internal password for the CopyReport database by using the --password parameter."); System.exit(0); } } } catch (ParseException exp) { System.out.println("Unexpected exception:" + exp.getMessage()); System.exit(0); } SongDatabaseConnector sdb = new SongDatabaseConnector(openlpPath); SongRepository cdb = new SongRepository(crPath + "/ccldata", "sa", crPassword); CopyReport rpt = new CopyReport(crDataPath + "/userdata", "sa", crPassword); //rpt.createPeriod("2014"); List<Song> songs = sdb.findLicensedSongs(); for (Song song : songs) { System.out.println(song.title + ": " + song.ccliNumber); if (song.ccliNumber.matches("-?\\d+(\\.\\d+)?")) { si = cdb.findById(song.ccliNumber); if (si != null) rpt.reportSong(si); } else { System.out.println("Format error: '" + song.ccliNumber + "' is not numeric."); } } // wrap up: close the databases cdb.close(); rpt.close(); sdb.close(); }
From source file:com.tomdoel.mpg2dcm.Xml2Dicom.java
public static void main(String[] args) { try {/* ww w. j a va 2 s. c om*/ final Options helpOptions = new Options(); helpOptions.addOption("h", false, "Print help for this application"); final DefaultParser parser = new DefaultParser(); final CommandLine commandLine = parser.parse(helpOptions, args); if (commandLine.hasOption('h')) { final String helpHeader = "Converts an endoscopic xml and video files to Dicom\n\n"; String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm"; final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Xml2Dcm xml-file dicom-output-path", helpHeader, helpOptions, helpFooter, true); } else { final List<String> remainingArgs = commandLine.getArgList(); if (remainingArgs.size() < 2) { throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified."); } final String xmlInputFileName = remainingArgs.get(0); final String dicomOutputPath = remainingArgs.get(1); EndoscopicXmlToDicomConverter.convert(new File(xmlInputFileName), dicomOutputPath); } } catch (org.apache.commons.cli.ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } }
From source file:io.github.tigertoes.DependencyMonkey.java
/** * @param args String//from ww w .java 2 s . com */ public static void main(String[] args) { Options options = new Options(); options.addOption("v", "verbose", false, "Verbose mode"); options.addOption("p", "pom-file", true, "Path to pom.xml"); }
From source file:com.huangyunkun.jviff.Runner.java
public static void main(String args[]) { Options options = new Options(); options.addOption("c", "config", true, "config file"); CommandLineParser parser = new PosixParser(); try {/*from w w w. j a v a2 s. c o m*/ CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("c")) { JViff jViff = new JViff(cmd.getOptionValue("c")); jViff.run(); } else { printHelp(options); } } catch (ParseException e) { printHelp(options); } catch (IOException e) { LOGGER.error("jviff face a error", e); } }
From source file:com.xandrev.altafitcalendargenerator.Main.java
public static void main(String[] args) { CalendarPrinter printer = new CalendarPrinter(); XLSExtractor extractor = new XLSExtractor(); if (args != null && args.length > 0) { try {//from w w w . j a va2 s . co m Options opt = new Options(); opt.addOption("f", true, "Filepath of the XLS file"); opt.addOption("t", true, "Type name of activities"); opt.addOption("m", true, "Month index"); opt.addOption("o", true, "Output filename of the generated ICS"); BasicParser parser = new BasicParser(); CommandLine cliParser = parser.parse(opt, args); if (cliParser.hasOption("f")) { String fileName = cliParser.getOptionValue("f"); LOG.debug("File name to be imported: " + fileName); String activityNames = cliParser.getOptionValue("t"); LOG.debug("Activity type names: " + activityNames); ArrayList<String> nameList = new ArrayList<>(); String[] actNames = activityNames.split(","); if (actNames != null) { nameList.addAll(Arrays.asList(actNames)); } LOG.debug("Sucessfully activities parsed: " + nameList.size()); if (cliParser.hasOption("m")) { String monthIdx = cliParser.getOptionValue("m"); LOG.debug("Month index: " + monthIdx); int month = Integer.parseInt(monthIdx) - 1; if (cliParser.hasOption("o")) { String outputfilePath = cliParser.getOptionValue("o"); LOG.debug("Output file to be generated: " + monthIdx); LOG.debug("Starting to extract the spreadsheet"); HashMap<Integer, ArrayList<TimeTrack>> result = extractor.importExcelSheet(fileName); LOG.debug("Extracted the spreadsheet done"); LOG.debug("Starting the filter of the data"); HashMap<Date, String> cal = printer.getCalendaryByItem(result, nameList, month); LOG.debug("Finished the filter of the data"); LOG.debug("Creating the ics Calendar"); net.fortuna.ical4j.model.Calendar calendar = printer.createICSCalendar(cal); LOG.debug("Finished the ics Calendar"); LOG.debug("Printing the ICS file to: " + outputfilePath); printer.saveCalendar(calendar, outputfilePath); LOG.debug("Finished the ICS file to: " + outputfilePath); } } } } catch (ParseException ex) { LOG.error("Error parsing the argument list: ", ex); } } }
From source file:io.proscript.jlight.JLight.java
public static void main(String[] args) throws IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); Option host = new Option("h", "host", true, "Host of the HTTP server (default 127.0.0.1)"); Option port = new Option("p", "port", true, "Port of the HTTP server (default 9000)"); Option main = new Option("c", "class", true, "Application to run, e.g. org.vendor.class"); Option help = new Option("h", "help", false, "Display help and exit"); Option version = new Option("v", "version", false, "Display JLight version"); options.addOption(host);/*from w w w. j av a 2 s . com*/ options.addOption(port); options.addOption(main); options.addOption(help); options.addOption(version); CommandLine line; try { line = parser.parse(options, args); if (line.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); Version.print(); formatter.printHelp("jlight", options); return; } if (line.hasOption("v")) { Version.print(); return; } if (!line.hasOption("c")) { throw new ParseException("Option 'class' is required"); } Runtime.run(line); } catch (ParseException exp) { System.err.println(exp.getMessage()); } }
From source file:com.github.jasmo.Bootstrap.java
public static void main(String[] args) { Options options = new Options().addOption("h", "help", false, "Print help message") .addOption("v", "verbose", false, "Increase verbosity") .addOption("c", "cfn", true, "Enable 'crazy fucking names and set name length (large names == large output size)'") .addOption("p", "package", true, "Move obfuscated classes to this package") .addOption("k", "keep", true, "Don't rename this class"); try {//from w w w. j a v a 2 s .com CommandLineParser clp = new DefaultParser(); CommandLine cl = clp.parse(options, args); if (cl.hasOption("help")) { help(options); return; } if (cl.hasOption("verbose")) { LoggerContext ctx = (LoggerContext) LogManager.getContext(false); Configuration config = ctx.getConfiguration(); LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); loggerConfig.setLevel(Level.DEBUG); ctx.updateLoggers(); } String[] keep = cl.getOptionValues("keep"); if (cl.getArgList().size() < 2) { throw new ParseException("Expected at-least two arguments"); } log.debug("Input: {}, Output: {}", cl.getArgList().get(0), cl.getArgList().get(1)); Obfuscator o = new Obfuscator(); try { o.supply(Paths.get(cl.getArgList().get(0))); } catch (Exception e) { log.error("An error occurred while reading the source target", e); return; } try { UniqueStringGenerator usg; if (cl.hasOption("cfn")) { int size = Integer.parseInt(cl.getOptionValue("cfn")); usg = new UniqueStringGenerator.Crazy(size); } else { usg = new UniqueStringGenerator.Default(); } o.apply(new FullAccessFlags()); o.apply(new ScrambleStrings()); o.apply(new ScrambleClasses(usg, cl.getOptionValue("package", ""), keep == null ? new String[0] : keep)); o.apply(new ScrambleFields(usg)); o.apply(new ScrambleMethods(usg)); o.apply(new InlineAccessors()); o.apply(new RemoveDebugInfo()); o.apply(new ShuffleMembers()); } catch (Exception e) { log.error("An error occurred while applying transform", e); return; } try { o.write(Paths.get(cl.getArgList().get(1))); } catch (Exception e) { log.error("An error occurred while writing to the destination target", e); return; } } catch (ParseException e) { log.error("Failed to parse command line arguments", e); help(options); } }
From source file:com.google.api.codegen.config.ConfigGeneratorTool.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "help", false, "show usage"); options.addOption(Option.builder().longOpt("descriptor_set") .desc("The descriptor set representing the compiled input protos.").hasArg() .argName("DESCRIPTOR-SET").required(true).build()); options.addOption(/*from www. j av a2s . c om*/ Option.builder("o").longOpt("output").desc("The directory in which to output the generated config.") .hasArg().argName("OUTPUT-FILE").required(true).build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("ConfigGeneratorTool", options); } generate(cl.getOptionValue("descriptor_set"), cl.getOptionValue("output")); }
From source file:com.github.braully.graph.UtilResult.java
public static void main(String... args) throws Exception { Options options = new Options(); Option input = new Option("i", "input", true, "input file path"); input.setRequired(false);// w ww .j a va2 s . c o m options.addOption(input); Option verb = new Option("v", "verbose", false, "verbose process"); input.setRequired(false); options.addOption(verb); Option output = new Option("o", "output", true, "output file"); output.setRequired(false); options.addOption(output); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("UtilResult", options); System.exit(1); return; } String inputFilePath = cmd.getOptionValue("input"); if (inputFilePath == null) { inputFilePath = "/home/strike/grafos-para-processar/mft2/resultado.txt"; } if (inputFilePath != null) { if (inputFilePath.toLowerCase().endsWith(".txt")) { processFileTxt(inputFilePath); } else if (inputFilePath.toLowerCase().endsWith(".json")) { processFileJson(inputFilePath); } } }
From source file:com.evolveum.midpoint.tools.gui.Main.java
public static void main(String[] args) throws Exception { Options options = new Options(); Option propertiesLocaleDelimiter = new Option("d", "delimiter", true, "Delimiter for locale name in properties file. Default is '_' (underscore)."); options.addOption(propertiesLocaleDelimiter); Option targetFolder = new Option("t", "targetFolder", true, "Target folder where properties file is generated."); targetFolder.setRequired(true);//from w w w. j a v a 2 s. co m options.addOption(targetFolder); Option baseFolder = new Option("b", "baseFolder", true, "Base folder used for properties files searching."); baseFolder.setRequired(true); options.addOption(baseFolder); Option localesToCheck = new Option("l", "locale", true, "Locales to check."); localesToCheck.setRequired(true); options.addOption(localesToCheck); Option recursiveFolderToCheck = new Option("r", "folderRecursive", true, "Folder used for recursive search for properties files."); options.addOption(recursiveFolderToCheck); Option nonRecursiveFolderToCheck = new Option("n", "folderNonRecursive", true, "Folder used for non recursive search for properties files."); options.addOption(nonRecursiveFolderToCheck); Option help = new Option("h", "help", false, "Print this help."); options.addOption(help); Option disableBackup = new Option("db", "disableBackup", false, "Disable backuping property files."); options.addOption(disableBackup); try { CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); if (line.hasOption(help.getOpt())) { printHelp(options); return; } if (!line.hasOption(recursiveFolderToCheck.getOpt()) && !line.hasOption(nonRecursiveFolderToCheck.getOpt())) { printHelp(options); return; } GeneratorConfiguration config = new GeneratorConfiguration(); if (line.hasOption(baseFolder.getOpt())) { config.setBaseFolder(new File(line.getOptionValue(baseFolder.getOpt()))); } if (line.hasOption(targetFolder.getOpt())) { config.setTargetFolder(new File(line.getOptionValue(targetFolder.getOpt()))); } if (line.hasOption(propertiesLocaleDelimiter.getOpt())) { config.setPropertiesLocaleDelimiter(line.getOptionValue(propertiesLocaleDelimiter.getOpt())); } if (line.hasOption(recursiveFolderToCheck.getOpt())) { String[] recursives = line.getOptionValues(recursiveFolderToCheck.getOpt()); if (recursives != null && recursives.length > 0) { for (String recursive : recursives) { config.getRecursiveFolderToCheck().add(recursive); } } } if (line.hasOption(nonRecursiveFolderToCheck.getOpt())) { String[] nonRecursives = line.getOptionValues(nonRecursiveFolderToCheck.getOpt()); if (nonRecursives != null && nonRecursives.length > 0) { for (String nonRecursive : nonRecursives) { config.getNonRecursiveFolderToCheck().add(nonRecursive); } } } if (line.hasOption(localesToCheck.getOpt())) { String[] locales = line.getOptionValues(localesToCheck.getOpt()); for (String locale : locales) { config.getLocalesToCheck().add(getLocaleFromString(locale)); } } if (line.hasOption(disableBackup.getOpt())) { config.setDisableBackup(true); } PropertiesGenerator generator = new PropertiesGenerator(config); generator.generate(); } catch (ParseException ex) { System.out.println("Error: " + ex.getMessage()); printHelp(options); } catch (Exception ex) { System.out.println("Something is broken."); ex.printStackTrace(); } }