List of usage examples for org.apache.commons.cli Options addOption
public Options addOption(String opt, boolean hasArg, String description)
From source file:com.google.infrastructuredmap.MapAndMarkdownExtractorMain.java
public static void main(String[] args) throws IOException, ParseException { Options options = new Options(); options.addOption(ARG_KML, true, "path to KML input"); options.addOption(ARG_MARKDOWN, true, "path to Markdown input"); options.addOption(ARG_JSON_OUTPUT, true, "path to write json output"); options.addOption(ARG_JSONP, true, "JSONP template to wrap output JSON data"); CommandLineParser parser = new DefaultParser(); CommandLine cli = parser.parse(options, args); // Extract map features from the input KML. MapData data = null;//w w w. j a v a 2 s . c om try (InputStream in = openStream(cli.getOptionValue(ARG_KML))) { Kml kml = Kml.unmarshal(in); data = MapDataExtractor.extractMapData(kml); } // Extract project features from the input Markdown. Map<String, List<ProjectReference>> references = MarkdownReferenceExtractor .extractReferences(Paths.get(cli.getOptionValue(ARG_MARKDOWN))); for (MapFeature feature : data.features) { List<ProjectReference> referencesForId = references.get(feature.id); if (referencesForId == null) { throw new IllegalStateException("Unknown project reference: " + feature.id); } feature.projects = referencesForId; } // Write the resulting data to the output path. Gson gson = new Gson(); try (FileWriter out = new FileWriter(cli.getOptionValue(ARG_JSON_OUTPUT))) { String json = gson.toJson(data); if (cli.hasOption(ARG_JSONP)) { json = String.format(cli.getOptionValue(ARG_JSONP), json); } out.write(json); } }
From source file:com.cloudera.flume.handlers.debug.TextToCollector.java
static public void main(String[] argv) throws IOException { Options opts = new Options(); opts.addOption("m", false, "Load events into memory"); opts.addOption("t", false, "Simple text file format loader"); opts.addOption("l", false, "Log4j text file format loader"); try {//w ww .j a v a 2s. com if (argv.length < 1) { HelpFormatter fmt = new HelpFormatter(); fmt.printHelp("TextToCollector", opts, true); System.exit(-1); } CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(opts, argv); core(cmd); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:it.serasoft.pdi.PDITools.java
public static void main(String[] args) throws Exception { Options opts = new Options(); opts.addOption("report", false, "Generate a report documenting the procedures under analysis"); opts.addOption("follow", true, "Values: directory, links, none"); opts.addOption("outDir", true, "Path to output directory where we will write eventual output files"); opts.addOption("srcDir", true, "Path to base directory containing the PDI processes source"); CommandLineParser parser = new DefaultParser(); CommandLine cmdLine = parser.parse(opts, args); String outDir = cmdLine.hasOption("outDir") ? cmdLine.getOptionValue("outDir") : null; String srcDir = cmdLine.hasOption("srcDir") ? cmdLine.getOptionValue("srcDir") : null; String follow = cmdLine.hasOption("follow") ? cmdLine.getOptionValue("follow") : FOLLOW_DIR; // Follow links between procedures only if required and recurseSubdir = false (DEFAULT) boolean recurseDir = follow.equals(FOLLOW_DIR); boolean followLinks = follow.equals(FOLLOW_PROCLINKS); startReadingDir(srcDir, recurseDir, followLinks); }
From source file:net.librec.tool.driver.RecDriver.java
public static void main(String[] args) throws Exception { LibrecTool tool = new RecDriver(); Options options = new Options(); options.addOption("build", false, "build model"); options.addOption("load", false, "load model"); options.addOption("save", false, "save model"); options.addOption("exec", false, "run job"); options.addOption("conf", true, "the path of configuration file"); options.addOption("jobconf", true, "a specified key-value pair for configuration"); options.addOption("D", true, "a specified key-value pair for configuration"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("build")) { ;/* www . j av a 2 s . co m*/ } else if (cmd.hasOption("load")) { ; } else if (cmd.hasOption("save")) { ; } else if (cmd.hasOption("exec")) { tool.run(args); } }
From source file:com.ibm.rdf.store.sparql11.DB2RDFQuery.java
public static void main(String[] args) { Options options = new Options(); try {// w ww .j a va 2 s .c o m // create Options object options.addOption("jdbcurl", true, "jdbc url"); options.addOption("schema", true, "schema name"); options.addOption("kb", true, "knowledge base"); options.addOption("username", true, "db user name"); options.addOption("password", true, "db password"); options.addOption("queryFile", true, "query file"); options.addOption("defaultUnionGraph", false, "default Union Graph semantics"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); boolean defUnion = cmd.hasOption("defaultUnionGraph") ? Boolean.parseBoolean(cmd.getOptionValue("defaultUnionGraph")) : false; DB2TestData data = new DB2TestData(cmd.getOptionValue("jdbcurl"), cmd.getOptionValue("kb"), cmd.getOptionValue("username"), cmd.getOptionValue("password"), cmd.getOptionValue("schemaName"), defUnion); DB2RDFQuery q = new DB2RDFQuery(new DB2Engine(), data); q.executeQuery(cmd.getOptionValue("queryFile")); } catch (Exception e) { e.printStackTrace(); HelpFormatter help = new HelpFormatter(); help.printHelp("DB2RDFQuery", options); } }
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 av a 2s.c o 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:com.adobe.aem.demomachine.Checksums.java
public static void main(String[] args) { String rootFolder = null;/*from ww w . j a v a 2 s . c o m*/ // Command line options for this tool Options options = new Options(); options.addOption("f", true, "Demo Machine root folder"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { rootFolder = cmd.getOptionValue("f"); } } catch (Exception e) { System.exit(-1); } Properties md5properties = new Properties(); List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths); for (String[] path : listPaths) { if (path.length == 5) { logger.debug(path[1]); File pathFolder = new File(rootFolder + (path[1].length() > 0 ? (File.separator + path[1]) : "")); if (pathFolder.exists()) { String md5 = AemDemoUtils.calcMD5HashForDir(pathFolder, Boolean.parseBoolean(path[3]), false); logger.debug("MD5 is: " + md5); md5properties.setProperty("demo.path." + path[0], path[1]); md5properties.setProperty("demo.md5." + path[0], md5); } else { logger.error("Folder cannot be found"); } } } File md5 = new File(rootFolder + File.separator + "conf" + File.separator + "checksums.properties"); try { @SuppressWarnings("serial") Properties tmpProperties = new Properties() { @Override public synchronized Enumeration<Object> keys() { return Collections.enumeration(new TreeSet<Object>(super.keySet())); } }; tmpProperties.putAll(md5properties); tmpProperties.store(new FileOutputStream(md5), null); } catch (Exception e) { logger.error(e.getMessage()); } System.out.println("MD5 checkums generated"); }
From source file:net.jingx.main.Main.java
/** * @param args// w w w . j a v a2 s . c om * @throws IOException */ public static void main(String[] args) { CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption(CLI_SECRET, true, "generate secret key (input is the configuration key from google)"); options.addOption(CLI_PASSCODE, true, "generate passcode (input is the secret key)"); options.addOption(new Option(CLI_HELP, "print this message")); try { CommandLine line = parser.parse(options, args); if (line.hasOption(CLI_SECRET)) { String confKey = line.getOptionValue(CLI_SECRET); String secret = generateSecret(confKey); System.out.println("Your secret to generate pins: " + secret); } else if (line.hasOption(CLI_PASSCODE)) { String secret = line.getOptionValue(CLI_PASSCODE); String pin = computePin(secret, null); System.out.println(pin); } else if (line.hasOption(CLI_HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("GAuthCli", options); } else { EventQueue.invokeLater(new Runnable() { public void run() { try { MainGui window = new MainGui(); window.doSetVisible(); } catch (Exception e) { e.printStackTrace(); } } }); return; } System.out.println("Press any key to exit"); System.in.read(); } catch (Exception e) { System.out.println("Unexpected exception:" + e.getMessage()); } System.exit(0); }
From source file:com.asual.lesscss.LessEngineCli.java
public static void main(String[] args) throws LessException, URISyntaxException { Options cmdOptions = new Options(); cmdOptions.addOption(LessOptions.CHARSET_OPTION, true, "Input file charset encoding. Defaults to UTF-8."); cmdOptions.addOption(LessOptions.COMPRESS_OPTION, false, "Flag that enables compressed CSS output."); cmdOptions.addOption(LessOptions.CSS_OPTION, false, "Flag that enables compilation of .css files."); cmdOptions.addOption(LessOptions.LESS_OPTION, true, "Path to a custom less.js for Rhino version."); try {//from w w w. j a v a2 s .com CommandLineParser cmdParser = new GnuParser(); CommandLine cmdLine = cmdParser.parse(cmdOptions, args); LessOptions options = new LessOptions(); if (cmdLine.hasOption(LessOptions.CHARSET_OPTION)) { options.setCharset(cmdLine.getOptionValue(LessOptions.CHARSET_OPTION)); } if (cmdLine.hasOption(LessOptions.COMPRESS_OPTION)) { options.setCompress(true); } if (cmdLine.hasOption(LessOptions.CSS_OPTION)) { options.setCss(true); } if (cmdLine.hasOption(LessOptions.LESS_OPTION)) { options.setLess(new File(cmdLine.getOptionValue(LessOptions.LESS_OPTION)).toURI().toURL()); } LessEngine engine = new LessEngine(options); if (System.in.available() != 0) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringWriter sw = new StringWriter(); char[] buffer = new char[1024]; int n = 0; while (-1 != (n = in.read(buffer))) { sw.write(buffer, 0, n); } String src = sw.toString(); if (!src.isEmpty()) { System.out.println(engine.compile(src, null, options.isCompress())); System.exit(0); } } String[] files = cmdLine.getArgs(); if (files.length == 1) { System.out.println(engine.compile(new File(files[0]), options.isCompress())); System.exit(0); } if (files.length == 2) { engine.compile(new File(files[0]), new File(files[1]), options.isCompress()); System.exit(0); } } catch (IOException ioe) { System.err.println("Error opening input file."); } catch (ParseException pe) { System.err.println("Error parsing arguments."); } String[] paths = LessEngine.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath() .split(File.separator); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar " + paths[paths.length - 1] + " input [output] [options]", cmdOptions); System.exit(1); }
From source file:com.benasmussen.tools.testeditor.ExtractorCLI.java
public static void main(String[] args) throws Exception { HelpFormatter formatter = new HelpFormatter(); // cli options Options options = new Options(); options.addOption(CMD_OPT_INPUT, true, "Input file"); // options.addOption(CMD_OPT_OUTPUT, true, "Output file"); try {/*from w w w . j av a 2 s .c o m*/ // evaluate command line options CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption(CMD_OPT_INPUT)) { // option value String optionValue = cmd.getOptionValue(CMD_OPT_INPUT); // input file File inputFile = new File(optionValue); // id extractor IdExtractor idExtractor = new IdExtractor(inputFile); Vector<Vector> data = idExtractor.parse(); // // TODO implement output folder // if (cmd.hasOption(CMD_OPT_OUTPUT)) // { // // file output // throw new Exception("Not implemented"); // } // else // { // console output System.out.println("Id;Value"); for (Vector vector : data) { StringBuilder sb = new StringBuilder(); if (vector.size() >= 1) { sb.append(vector.get(0)); } sb.append(";"); if (vector.size() >= 2) { sb.append(vector.get(1)); } System.out.println(sb.toString()); } // } } else { throw new IllegalArgumentException(); } } catch (ParseException e) { formatter.printHelp("ExtractorCLI", options); } catch (IllegalArgumentException e) { formatter.printHelp("ExtractorCLI", options); } }