List of usage examples for org.apache.commons.cli CommandLine hasOption
public boolean hasOption(char opt)
From source file:net.anthonypoon.ngram.correlation.Main.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("a", "action", true, "Action"); options.addOption("i", "input", true, "input"); options.addOption("o", "output", true, "output"); //options.addOption("f", "format", true, "Format"); options.addOption("u", "upbound", true, "Year up bound"); options.addOption("l", "lowbound", true, "Year low bound"); options.addOption("t", "target", true, "Correlation Target URI"); // Can only take file from S# or HDFS options.addOption("L", "lag", true, "Lag factor"); options.addOption("T", "threshold", true, "Correlation threshold"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); Configuration conf = new Configuration(); if (cmd.hasOption("lag")) { conf.set("lag", cmd.getOptionValue("lag")); }/*from w w w. j ava 2 s. c o m*/ if (cmd.hasOption("threshold")) { conf.set("threshold", cmd.getOptionValue("threshold")); } if (cmd.hasOption("upbound")) { conf.set("upbound", cmd.getOptionValue("upbound")); } else { conf.set("upbound", "9999"); } if (cmd.hasOption("lowbound")) { conf.set("lowbound", cmd.getOptionValue("lowbound")); } else { conf.set("lowbound", "0"); } if (cmd.hasOption("target")) { conf.set("target", cmd.getOptionValue("target")); } else { throw new Exception("Missing correlation target file uri"); } Job job = Job.getInstance(conf); /** if (cmd.hasOption("format")) { switch (cmd.getOptionValue("format")) { case "compressed": job.setInputFormatClass(SequenceFileAsTextInputFormat.class); break; case "text": job.setInputFormatClass(KeyValueTextInputFormat.class); break; } }**/ job.setJarByClass(Main.class); switch (cmd.getOptionValue("action")) { case "get-correlation": job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); for (String inputPath : cmd.getOptionValue("input").split(",")) { MultipleInputs.addInputPath(job, new Path(inputPath), KeyValueTextInputFormat.class, CorrelationMapper.class); } job.setReducerClass(CorrelationReducer.class); break; default: throw new IllegalArgumentException("Missing action"); } String timestamp = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()); //FileInputFormat.setInputPaths(job, new Path(cmd.getOptionValue("input"))); FileOutputFormat.setOutputPath(job, new Path(cmd.getOptionValue("output") + "/" + timestamp)); System.exit(job.waitForCompletion(true) ? 0 : 1); }
From source file:com.datazuul.iiif.presentation.api.ManifestGenerator.java
public static void main(String[] args) throws ParseException, JsonProcessingException, IOException, URISyntaxException { Options options = new Options(); options.addOption("d", true, "Absolute file path to the directory containing the image files."); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("d")) { String imageDirectoryPath = cmd.getOptionValue("d"); Path imageDirectory = Paths.get(imageDirectoryPath); final List<Path> files = new ArrayList<>(); try {/*from w ww. j av a2s. c om*/ Files.walkFileTree(imageDirectory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!attrs.isDirectory()) { // TODO there must be a more elegant solution for filtering jpeg files... if (file.getFileName().toString().endsWith("jpg")) { files.add(file); } } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); } Collections.sort(files, new Comparator() { @Override public int compare(Object fileOne, Object fileTwo) { String filename1 = ((Path) fileOne).getFileName().toString(); String filename2 = ((Path) fileTwo).getFileName().toString(); try { // numerical sorting Integer number1 = Integer.parseInt(filename1.substring(0, filename1.lastIndexOf("."))); Integer number2 = Integer.parseInt(filename2.substring(0, filename2.lastIndexOf("."))); return number1.compareTo(number2); } catch (NumberFormatException nfe) { // alpha-numerical sorting return filename1.compareToIgnoreCase(filename2); } } }); generateManifest(imageDirectory.getFileName().toString(), files); } else { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ManifestGenerator", options); } }
From source file:com.zimbra.cs.mailbox.calendar.FixCalendarEndTimeUtil.java
public static void main(String[] args) { CliUtil.toolSetup();//from ww w . j a v a 2s . com FixCalendarEndTimeUtil util = null; try { util = new FixCalendarEndTimeUtil(); } catch (ServiceException e) { System.err.println(e.getMessage()); System.exit(1); } try { CommandLine cl = util.getCommandLine(args); if (cl == null) return; util.doit(getZAuthToken(cl), cl.getOptionValues(O_ACCOUNT), cl.hasOption(O_SYNC)); System.exit(0); } catch (ParseException e) { util.usage(e); } catch (Exception e) { System.err.println("Error occurred: " + e.getMessage()); util.usage(null); } System.exit(1); }
From source file:com.zimbra.cs.mailbox.calendar.FixCalendarPriorityUtil.java
public static void main(String[] args) { CliUtil.toolSetup();// w w w. j av a 2s .c o m FixCalendarPriorityUtil util = null; try { util = new FixCalendarPriorityUtil(); } catch (ServiceException e) { System.err.println(e.getMessage()); System.exit(1); } try { CommandLine cl = util.getCommandLine(args); if (cl == null) return; util.doit(getZAuthToken(cl), cl.getOptionValues(O_ACCOUNT), cl.hasOption(O_SYNC)); System.exit(0); } catch (ParseException e) { util.usage(e); } catch (Exception e) { System.err.println("Error occurred: " + e.getMessage()); util.usage(null); } System.exit(1); }
From source file:edu.msu.cme.rdp.framebot.stat.TaxonAbundance.java
/** * this class group the nearest matches by phylum/class, or by match * @param args//www.ja v a2 s . c o m * @throws Exception */ public static void main(String[] args) throws Exception { HashMap<String, Double> coveragetMap = null; double identity = 0.0; try { CommandLine line = new PosixParser().parse(options, args); if (line.hasOption("seqCoverage")) { String coveragefile = line.getOptionValue("seqCoverage"); coveragetMap = parseKmerCoverage(coveragefile); } if (line.hasOption("identity")) { identity = Double.parseDouble(line.getOptionValue("identity")); if (identity < 0 || identity > 100) { throw new IllegalArgumentException("identity cutoff should be in the range of 0 and 100"); } } args = line.getArgs(); if (args.length != 3) { throw new Exception(""); } } catch (Exception e) { System.out.println("Command Error: " + e.getMessage()); new HelpFormatter().printHelp(80, "[options] <FrameBot Alignment file or Dir> <seqLineage> <out file> ", "", options, "seqLineage: a tab-delimited file with ref seqID and lineage, or fasta of ref seq with lineage as the descrption" + "\nframeBot alignment file or Dir: frameBot alignment files " + "\noutfile: output with the nearest match count group by phylum/class; and by match name"); } TaxonAbundance.mapAbundance(new File(args[0]), new File(args[1]), args[2], coveragetMap, identity); }
From source file:com.c4om.xsdfriendlyvalidator.XSDFriendlyValidatorLauncher.java
/** * Method called at application start./*from w w w .ja va 2 s . co m*/ * * @param args command line args */ public static void main(String[] args) throws Exception { CommandLineParser parser = new BasicParser(); CommandLine commandLine1 = parser.parse(OPTIONS, args); CommandLine commandLine = commandLine1; if (commandLine.hasOption(OPTION_NAME_HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(COMMAND_LINE_SYNTAX, OPTIONS); System.exit(0); } else if (!commandLine.hasOption(OPTION_NAME_INPUT_FILES)) { System.err.println("You must specify input files. Invoke with --help to see how."); System.exit(1); } String[] inputFileOptionValues = commandLine.getOptionValues(OPTION_NAME_INPUT_FILES); List<Document> inputFilesList = getListOfInputDocumentsFromCommandLine(inputFileOptionValues); String[] schemasOptionValues = commandLine.getOptionValues(OPTION_NAME_SCHEMAS); Map<String, Document> schemasMap = getSchemaFilesFromCommandLine(schemasOptionValues); XSDFriendlyValidator validator = new XSDFriendlyValidatorImpl(); ValidationResults validationResults = validator.validate(inputFilesList, Arrays.asList(inputFileOptionValues), schemasMap); System.out.println(validationResults.toString()); }
From source file:gr.seab.r2rml.beans.Main.java
public static void main(String[] args) { Calendar c0 = Calendar.getInstance(); long t0 = c0.getTimeInMillis(); CommandLineParser cmdParser = new PosixParser(); Options cmdOptions = new Options(); cmdOptions.addOption("p", "properties", true, "define the properties file. Example: r2rml-parser -p r2rml.properties"); cmdOptions.addOption("h", "print help", false, "help"); String propertiesFile = "r2rml.properties"; try {/*from www . j a v a 2 s. co m*/ CommandLine line = cmdParser.parse(cmdOptions, args); if (line.hasOption("h")) { HelpFormatter help = new HelpFormatter(); help.printHelp("r2rml-parser\n", cmdOptions); System.exit(0); } if (line.hasOption("p")) { propertiesFile = line.getOptionValue("p"); } } catch (ParseException e1) { //e1.printStackTrace(); log.error("Error parsing command line arguments."); System.exit(1); } try { if (StringUtils.isNotEmpty(propertiesFile)) { properties.load(new FileInputStream(propertiesFile)); log.info("Loaded properties from " + propertiesFile); } } catch (FileNotFoundException e) { //e.printStackTrace(); log.error("Properties file not found (" + propertiesFile + ")."); System.exit(1); } catch (IOException e) { //e.printStackTrace(); log.error("Error reading properties file (" + propertiesFile + ")."); System.exit(1); } ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("app-context.xml"); Database db = (Database) context.getBean("db"); db.setProperties(properties); Parser parser = (Parser) context.getBean("parser"); parser.setProperties(properties); MappingDocument mappingDocument = parser.parse(); mappingDocument.getTimestamps().add(t0); //0 Started mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //1 Finished parsing. Starting generating result model. Generator generator = (Generator) context.getBean("generator"); generator.setProperties(properties); generator.setResultModel(parser.getResultModel()); //Actually do the output generator.createTriples(mappingDocument); context.close(); Calendar c1 = Calendar.getInstance(); long t1 = c1.getTimeInMillis(); log.info("Finished in " + (t1 - t0) + " milliseconds. Done."); mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //5 Finished. //log.info("5 Finished."); //output the result for (int i = 0; i < mappingDocument.getTimestamps().size(); i++) { if (i > 0) { long l = (mappingDocument.getTimestamps().get(i).longValue() - mappingDocument.getTimestamps().get(i - 1).longValue()); //System.out.println(l); log.info(String.valueOf(l)); } } log.info("Parse. Generate in memory. Dump to disk/database. Log. - Alltogether in " + String.valueOf(mappingDocument.getTimestamps().get(5).longValue() - mappingDocument.getTimestamps().get(0).longValue()) + " msec."); log.info("Done."); System.out.println("Done."); }
From source file:it.codestudio.callbyj.CallByJ.java
/** * The main method./*from ww w. j av a2 s .c om*/ * * @param args the arguments */ public static void main(String[] args) { options.addOption("aCom", "audio_com", true, "Specify serial COM port for audio streaming (3G APPLICATION ...)"); options.addOption("cCom", "command_com", true, "Specify serial COM port for modem AT command (PC UI INTERFACE ...)"); options.addOption("p", "play_message", false, "Play recorded message instead to respond with audio from mic"); options.addOption("h", "help", false, "Print help for this application"); try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String audioCOM = ""; String commandCOM = ""; Boolean playMessage = false; args = Utils.fitlerNullString(args); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("aCom")) { audioCOM = cmd.getOptionValue("aCom"); ; } if (cmd.hasOption("cCom")) { commandCOM = cmd.getOptionValue("cCom"); ; } if (cmd.hasOption("p")) { playMessage = true; } if (audioCOM != null && commandCOM != null && !audioCOM.isEmpty() && !commandCOM.isEmpty()) { comManager = ComManager.getInstance(commandCOM, audioCOM, playMessage); } else { HelpFormatter f = new HelpFormatter(); f.printHelp("\r Exaple: CallByJ -aCom COM11 -cCom COM10 \r OptionsTip", options); return; } options = new Options(); options.addOption("h", "help", false, "Print help for this application"); options.addOption("p", "pin", true, "Specify pin of device, if present"); options.addOption("c", "call", true, "Start call to specified number"); options.addOption("e", "end", false, "End all active call"); options.addOption("t", "terminate", false, "Terminate application"); options.addOption("r", "respond", false, "Respond to incoming call"); comManager.startModemCommandManager(); while (true) { try { String[] commands = { br.readLine() }; commands = Utils.fitlerNullString(commands); cmd = parser.parse(options, commands); if (cmd.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp("OptionsTip", options); } if (cmd.hasOption('p')) { String devicePin = cmd.getOptionValue("p"); comManager.insertPin(devicePin); } if (cmd.hasOption('c')) { String numberToCall = cmd.getOptionValue("c"); comManager.sendCommandToModem(ATCommands.CALL, numberToCall); } if (cmd.hasOption('r')) { comManager.respondToIncomingCall(); } if (cmd.hasOption('e')) { comManager.sendCommandToModem(ATCommands.END_CALL); } if (cmd.hasOption('t')) { comManager.sendCommandToModem(ATCommands.END_CALL); comManager.terminate(); System.out.println("CallByJ closed!"); break; //System.exit(0); } } catch (Exception e) { logger.error(e.getMessage(), e); } } } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (comManager != null) comManager.terminate(); } }
From source file:com.chip8java.emulator.Runner.java
/** * Runs the emulator with the specified command line options. * /*from www. j a v a2s .c o m*/ * @param argv * The set of options passed to the emulator */ public static void main(String[] argv) { CommandLine commandLine = parseCommandLineOptions(argv); Emulator.Builder emulatorBuilder = new Emulator.Builder(); if (commandLine.hasOption(HELP_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("emulator", generateOptions()); System.exit(0); } if (commandLine.hasOption(SCALE_OPTION)) { int scale = Integer.parseInt(commandLine.getOptionValue(SCALE_OPTION)); emulatorBuilder.setScale(scale); } String[] args = commandLine.getArgs(); if (args.length != 0) { emulatorBuilder.setRom(args[0]); } if (commandLine.hasOption(TRACE_OPTION)) { emulatorBuilder.setTrace(); } if (commandLine.hasOption(DELAY_OPTION)) { int delay = Integer.parseInt(commandLine.getOptionValue(DELAY_OPTION)); emulatorBuilder.setCycleTime((long) delay); } Emulator emulator = emulatorBuilder.build(); emulator.start(); }
From source file:ar.com.ergio.uncoma.cei.MiniPas.java
/** * @param args/*w w w . ja v a 2s . c om*/ * @throws IOException */ @SuppressWarnings("static-access") public static void main(String[] args) throws IOException { // Config logging system -- TODO improve this Handler console = new ConsoleHandler(); ROOT_LOG.addHandler(console); // Create cmdline options - TODO - I18N final Options options = new Options(); options.addOption(new Option("help", "Muestra este mensaje")); options.addOption(new Option("version", "Muestra la informaci\u00f3 de versi\u00f3n y termina")); options.addOption(new Option("debug", "Muestra informaci\u00f3n para depuraci\u00f3n")); options.addOption( OptionBuilder.withArgName("file").hasArg().withDescription("Archivo de log").create("logFile")); final CommandLineParser cmdlineParser = new GnuParser(); final HelpFormatter formatter = new HelpFormatter(); try { final CommandLine cmdline = cmdlineParser.parse(options, args); // Process command line args -- TODO Improve this if (args.length == 0 || cmdline.hasOption("help")) { formatter.printHelp("minipas", options, true); } else if (cmdline.hasOption("version")) { System.out.println("MiniPas versi\u00f3n: 0.0.1"); } else if (cmdline.hasOption("debug")) { ROOT_LOG.setLevel(Level.FINE); } else { ROOT_LOG.fine("Arguments: " + Arrays.toString(args)); final Scanner scanner = new Scanner(args[0]); while (scanner.hasTokens()) { System.out.println(scanner.nextToken()); } } } catch (ParseException e) { formatter.printHelp("minipas", options, true); } }