List of usage examples for org.apache.commons.cli CommandLine getOptionValues
public String[] getOptionValues(char opt)
From source file:be.i8c.sag.documentationgenerator.cli.Arguments.java
public Arguments(CommandLine commandLine) throws IllegalArgumentException { // Required//w w w . j ava 2s . c om PACKAGE_DIR = commandLine.getOptionValue(Names.PACKAGE_DIR_LONG); if (PACKAGE_DIR == null) throw new IllegalArgumentException( Names.PACKAGE_DIR_LONG + " (" + Names.PACKAGE_DIR + ") is a required argument!"); log("PACKAGE_DIR", PACKAGE_DIR); // Have default values OUTPUT_DIR = commandLine.getOptionValue(Names.OUTPUT_DIR_LONG, DefaultValues.OUTPUT_DIR); log("OUTPUT_DIR", OUTPUT_DIR); PACKAGE_NAME_REGEX = commandLine.getOptionValue(Names.PACKAGE_NAME_REGEX_LONG, DefaultValues.PACKAGE_NAME_REGEX); log("PACKAGE_NAME_REGEX", PACKAGE_NAME_REGEX); String[] packageNames = commandLine.getOptionValues(Names.PACKAGE_NAMES_LONG); if (packageNames == null) PACKAGE_NAMES = DefaultValues.PACKAGE_NAMES; else PACKAGE_NAMES = packageNames; log("PACKAGE_NAMES", PACKAGE_NAMES); FOLDER_QUALIFIER_NAME_REGEX = commandLine.getOptionValue(Names.FOLDER_QUALIFIER_NAME_REGEX_LONG, DefaultValues.FOLDER_QUALIFIER_NAME_REGEX); log("FOLDER_QUALIFIER_NAME_REGEX", FOLDER_QUALIFIER_NAME_REGEX); // Are optional XSLT_DIR = commandLine.getOptionValue(Names.XSLT_DIR_LONG); log("XSLT_DIR", XSLT_DIR); CONFIG_DIR = commandLine.getOptionValue(Names.CONFIG_DIR_LONG); log("CONFIG_DIR", CONFIG_DIR); // Options are either present or not GENERATE_XML = commandLine.hasOption(Names.GENERATE_XML_LONG); log("GENERATE_XML", GENERATE_XML); GENERATE_PDF = commandLine.hasOption(Names.GENERATE_PDF_LONG); log("GENERATE_PDF", GENERATE_PDF); GENERATE_HTML = commandLine.hasOption(Names.GENERATE_HTML_LONG); log("GENERATE_HTML", GENERATE_HTML); GENERATE_MD = commandLine.hasOption(Names.GENERATE_MD_LONG); log("GENERATE_MD", GENERATE_MD); GENERATE_TXT = commandLine.hasOption(Names.GENERATE_TXT_LONG); log("GENERATE_TXT", GENERATE_TXT); INTERMEDIATE_XML = commandLine.hasOption(Names.INTERMEDIATE_XML_LONG); log("INTERMEDIATE_XML", INTERMEDIATE_XML); }
From source file:com.axelor.shell.core.Target.java
public Object[] findArguments(String[] args) { final List<Object> arguments = new ArrayList<>(method.getParameterTypes().length); final Options options = getOptions(); final CommandLineParser lineParser = new BasicParser(); final CommandLine cmdLine; try {//from w ww . ja v a 2s.c o m cmdLine = lineParser.parse(options, args); } catch (ParseException e) { System.out.println(); System.out.println(e.getMessage()); System.out.println(); return null; } for (CliOption cliOption : cliOptions) { if (cliOption == null) { arguments.add(cmdLine.getArgs()); continue; } String key = "" + cliOption.shortName(); if (isBlank(key)) { key = cliOption.name(); } Option opt = options.getOption(key); Object value = false; if (opt.hasArgs()) { value = cmdLine.getOptionValues(key); } else if (opt.hasArg()) { value = cmdLine.getOptionValue(key); } else { value = cmdLine.hasOption(key); } arguments.add(value); } return arguments.toArray(); }
From source file:bdsup2sub.cli.CommandLineParser.java
private void parseMoveYOption(CommandLine line) throws ParseException { if (line.hasOption(MOVE_IN) || line.hasOption(MOVE_OUT)) { moveModeY = line.hasOption(MOVE_IN) ? Optional.of(CaptionMoveModeY.MOVE_INSIDE_BOUNDS) : Optional.of(CaptionMoveModeY.MOVE_OUTSIDE_BOUNDS); String option = line.hasOption(MOVE_IN) ? MOVE_IN : MOVE_OUT; if (line.getOptionValues(option).length != 2) { throw new ParseException("2 arguments needed for moving captions."); }//w ww . j av a2 s .c om screenRatio = ToolBox.getDouble(line.getOptionValues(option)[0]); if (screenRatio <= (16.0 / 9)) { throw new ParseException("Invalid screen ratio: " + screenRatio); } moveYOffset = ToolBox.getInt(line.getOptionValues(option)[1]); if (moveYOffset < 0) { throw new ParseException("Invalid pixel offset: " + moveYOffset); } } }
From source file:eu.stratosphere.client.CliFrontend.java
/** * @param line// w w w. j av a2s. c om * * @return Either a PackagedProgram (upon success), or null; */ protected PackagedProgram buildProgram(CommandLine line) { String[] programArgs = line.hasOption(ARGS_OPTION.getOpt()) ? line.getOptionValues(ARGS_OPTION.getOpt()) : line.getArgs(); // take the jar file from the option, or as the first trailing parameter (if available) String jarFilePath = null; if (line.hasOption(JAR_OPTION.getOpt())) { jarFilePath = line.getOptionValue(JAR_OPTION.getOpt()); } else if (programArgs.length > 0) { jarFilePath = programArgs[0]; programArgs = Arrays.copyOfRange(programArgs, 1, programArgs.length); } else { System.out.println("Error: Jar file is not set."); return null; } File jarFile = new File(jarFilePath); // Check if JAR file exists if (!jarFile.exists()) { System.out.println("Error: Jar file does not exist."); return null; } else if (!jarFile.isFile()) { System.out.println("Error: Jar file is not a file."); return null; } // Get assembler class String entryPointClass = line.hasOption(CLASS_OPTION.getOpt()) ? line.getOptionValue(CLASS_OPTION.getOpt()) : null; try { return entryPointClass == null ? new PackagedProgram(jarFile, programArgs) : new PackagedProgram(jarFile, entryPointClass, programArgs); } catch (ProgramInvocationException e) { handleError(e); return null; } }
From source file:hws.core.ExecutorThread.java
public void run(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, ParseException { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("app-id").withDescription("String of the Application Id") .hasArg().withArgName("AppId").create("aid")); options.addOption(OptionBuilder.withLongOpt("container-id").withDescription("String of the Container Id") .hasArg().withArgName("ContainerId").create("cid")); options.addOption(OptionBuilder.withLongOpt("load").withDescription("load module instance").hasArg() .withArgName("Json-Base64").create()); options.addOption(OptionBuilder.withLongOpt("zk-servers").withDescription("List of the ZooKeeper servers") .hasArgs().withArgName("zkAddrs").create("zks")); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); String appIdStr = null;//from w w w .j a v a 2s . com String containerIdStr = null; String instanceInfoBase64 = null; String instanceInfoJson = null; InstanceInfo instanceInfo = null; if (cmd.hasOption("aid")) { appIdStr = cmd.getOptionValue("aid"); } if (cmd.hasOption("cid")) { containerIdStr = cmd.getOptionValue("cid"); } String zksArgs = ""; String[] zkServers = null; if (cmd.hasOption("zks")) { zksArgs = "-zks"; zkServers = cmd.getOptionValues("zks"); for (String zks : zkServers) { zksArgs += " " + zks; } } //Logger setup Configuration conf = new Configuration(); FileSystem fileSystem = FileSystem.get(conf); FSDataOutputStream writer = fileSystem .create(new Path("hdfs:///hws/apps/" + appIdStr + "/logs/" + containerIdStr + ".log")); Logger.addOutputStream(writer); Logger.info("Processing Instance"); if (cmd.hasOption("load")) { instanceInfoBase64 = cmd.getOptionValue("load"); instanceInfoJson = StringUtils.newStringUtf8(Base64.decodeBase64(instanceInfoBase64)); instanceInfo = Json.loads(instanceInfoJson, InstanceInfo.class); } Logger.info("Instance info: " + instanceInfoJson); this.latch = new CountDownLatch(instanceInfo.inputChannels().keySet().size()); Logger.info("Latch Countdowns: " + instanceInfo.inputChannels().keySet().size()); ZkClient zk = new ZkClient(zkServers[0]); //TODO select a ZooKeeper server Logger.info("Load Instance " + instanceInfo.instanceId()); loadInstance(instanceInfo, zk, "/hadoop-watershed/" + appIdStr + "/"); IZkChildListener producersHaltedListener = createProducersHaltedListener(); String znode = "/hadoop-watershed/" + appIdStr + "/" + instanceInfo.filterInfo().name() + "/halted"; Logger.info("halting znode: " + znode); zk.subscribeChildChanges(znode, producersHaltedListener); ExecutorService serverExecutor = Executors.newCachedThreadPool(); //wait for a start command from the ApplicationMaster via ZooKeeper znode = "/hadoop-watershed/" + appIdStr + "/" + instanceInfo.filterInfo().name() + "/start"; Logger.info("starting znode: " + znode); zk.waitUntilExists(znode, TimeUnit.MILLISECONDS, 250); Logger.info("Exists: " + zk.exists(znode)); /* while(!zk.waitUntilExists(znode,TimeUnit.MILLISECONDS, 500)){ //out.println("TIMEOUT waiting for start znode: "+znode); //out.flush(); }*/ //start and execute this instance Logger.info("Starting Instance"); startExecutors(serverExecutor); Logger.info("Instance STARTED"); Logger.info("Waiting TERMINATION"); try { this.latch.await(); //await the input threads to finish } catch (InterruptedException e) { // handle Logger.severe("Waiting ERROR: " + e.getMessage()); } Logger.info("Finishing Instance"); finishExecutors(); Logger.info("FINISHED Instance " + instanceInfo.instanceId()); String finishZnode = "/hadoop-watershed/" + appIdStr + "/" + instanceInfo.filterInfo().name() + "/finish/" + instanceInfo.instanceId(); zk.createPersistent(finishZnode, ""); }
From source file:fr.inrialpes.exmo.align.cli.GroupOutput.java
public void run(String[] args) throws Exception { try {//from w ww . j a va 2s .c o m CommandLine line = parseCommandLine(args); if (line == null) return; // --help // Here deal with command specific arguments if (line.hasOption('v')) values = true; if (line.hasOption('e')) labels = true; if (line.hasOption('c')) color = line.getOptionValue('c', "blue"); if (line.hasOption('t')) type = line.getOptionValue('t'); if (line.hasOption('l')) listAlgo = line.getOptionValues('l'); if (line.hasOption('f')) { String s = line.getOptionValue('f'); if (s.equals("p")) measure = 1; else if (s.equals("r")) measure = 2; else if (s.equals("o")) measure = 3; } if (line.hasOption('w')) ontoDir = line.getOptionValue('w'); } catch (ParseException exp) { logger.error(exp.getMessage()); usage(); System.exit(-1); } parameters.setProperty("step", Integer.toString(SIZE)); try { File dir = null; if (ontoDir == null) { dir = new File(System.getProperty("user.dir")); } else { dir = new File(ontoDir); } prefix = dir.toURI().toString(); } catch (Exception e) { logger.error("Cannot stat dir ", e); usage(); System.exit(-1); } // Set output file OutputStream stream; if (outputfilename == null) { stream = System.out; } else { stream = new FileOutputStream(outputfilename); } output = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream, "UTF-8")), true); // Header if (type.equals("tex")) { output.println("\\documentclass[11pt]{book}"); output.println(); output.println("\\usepackage{pgf}"); output.println("\\usepackage{tikz}"); output.println("\\usepackage{pgflibraryshapes}"); output.println(); output.println("\\begin{document}"); output.println("\\date{today}"); output.println(""); } // Process iterateAlgorithm(); // Trailer if (type.equals("tex")) { output.println("\\end{document}"); output.println(); } }
From source file:com.emc.ecs.sync.config.ConfigWrapper.java
public C parse(CommandLine commandLine, String prefix) { try {//from www .j a v a 2 s .c o m C object = getTargetClass().newInstance(); BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(object); for (String name : propertyNames()) { ConfigPropertyWrapper propertyWrapper = getPropertyWrapper(name); if (!propertyWrapper.isCliOption()) continue; org.apache.commons.cli.Option option = propertyWrapper.getCliOption(prefix); if (commandLine.hasOption(option.getLongOpt())) { Object value = commandLine.getOptionValue(option.getLongOpt()); if (propertyWrapper.getDescriptor().getPropertyType().isArray()) value = commandLine.getOptionValues(option.getLongOpt()); if (Boolean.class == propertyWrapper.getDescriptor().getPropertyType() || "boolean".equals(propertyWrapper.getDescriptor().getPropertyType().getName())) value = Boolean.toString(!propertyWrapper.isCliInverted()); beanWrapper.setPropertyValue(name, value); } } return object; } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } }
From source file:com.gmarciani.gmparser.controllers.App.java
/** * <p>The app entry-point method.<p> * <p>This method is activated when no arguments neither options are specified.<p> * /*www. j a va 2s . com*/ * @param args command-line arguments. * @throws ParseException */ public void play(String[] args) throws ParseException { CommandLineParser cmdParser = new GnuParser(); CommandLine cmd = cmdParser.parse(this.options, args); String unrecognizedArguments[] = cmd.getArgs(); if (unrecognizedArguments.length != 0) { this.getOutput().onUnrecognizedArguments(unrecognizedArguments); this.quit(); } if (cmd.getOptions().length == 0) { boolean loop = true; while (loop) { this.playMenu(); loop = this.getContinued(); } } else if (cmd.hasOption("analyze")) { final String vals[] = cmd.getOptionValues("analyze"); final String grammar = vals[0]; if (!this.validateGrammar(grammar)) return; this.analyze(grammar); } else if (cmd.hasOption("transform")) { final String vals[] = cmd.getOptionValues("transform"); final GrammarTransformation transformation = GrammarTransformation.valueOf(vals[0]); final String grammar = vals[1]; if (!this.validateGrammar(grammar)) return; this.transform(grammar, transformation); } else if (cmd.hasOption("parse")) { final String vals[] = cmd.getOptionValues("parse"); final ParserType parserType = ParserType.valueOf(vals[0]); final String word = (vals[1] == null || vals[1].equals(Grammar.EPSILON.toString())) ? "" : vals[1]; final String grammar = vals[2]; if (!this.validateGrammar(grammar)) return; this.parse(grammar, word, parserType); } else if (cmd.hasOption("help")) { this.help(); } else if (cmd.hasOption("version")) { this.version(); } this.quit(); }
From source file:com.eviware.soapui.tools.SoapUIMockServiceRunner.java
@Override protected boolean processCommandLine(CommandLine cmd) { if (cmd.hasOption("m")) setMockService(getCommandLineOptionSubstSpace(cmd, "m")); if (cmd.hasOption("a")) setPath(getCommandLineOptionSubstSpace(cmd, "a")); if (cmd.hasOption("p")) setPort(cmd.getOptionValue("p")); if (cmd.hasOption("s")) setSettingsFile(getCommandLineOptionSubstSpace(cmd, "s")); setBlock(!cmd.hasOption('b')); setSaveAfterRun(cmd.hasOption('S')); if (cmd.hasOption("x")) { setProjectPassword(cmd.getOptionValue("x")); }/* ww w . j a va 2 s .co m*/ if (cmd.hasOption("v")) { setSoapUISettingsPassword(cmd.getOptionValue("v")); } if (cmd.hasOption("D")) { setSystemProperties(cmd.getOptionValues("D")); } if (cmd.hasOption("G")) { setGlobalProperties(cmd.getOptionValues("G")); } if (cmd.hasOption("P")) { setProjectProperties(cmd.getOptionValues("P")); } return true; }
From source file:fr.inrialpes.exmo.align.cli.GenPlot.java
public void run(String[] args) throws Exception { String evalCN = "fr.inrialpes.exmo.align.impl.eval.PRecEvaluator"; String graphCN = "fr.inrialpes.exmo.align.impl.eval.PRGraphEvaluator"; try {// w w w. j a va2 s .com CommandLine line = parseCommandLine(args); if (line == null) return; // --help // Here deal with command specific arguments if (line.hasOption('e')) evalCN = line.getOptionValue('e'); if (line.hasOption('g')) graphCN = line.getOptionValue('g'); if (line.hasOption('t')) type = line.getOptionValue('t'); if (line.hasOption('l')) { listAlgo = line.getOptionValues('l'); size = listAlgo.length; } if (line.hasOption('w')) ontoDir = line.getOptionValue('w'); } catch (ParseException exp) { logger.error(exp.getMessage()); usage(); System.exit(-1); } Class<?> graphClass = Class.forName(graphCN); Class<?>[] cparams = {}; graphConstructor = graphClass.getConstructor(cparams); // JE: This is not used Class<?> evalClass = Class.forName(evalCN); Class<?>[] caparams = { Alignment.class, Alignment.class }; evalConstructor = evalClass.getConstructor(caparams); // Collect correspondences from alignments in all directories // . -> Vector<EvalCell> listEvaluators = iterateDirectories(); // Find the largest value int max = 0; for (GraphEvaluator e : listEvaluators) { int n = e.nbCells(); if (n > max) max = n; } parameters.setProperty("scale", Integer.toString(max)); xlabel = listEvaluators.get(0).xlabel(); ylabel = listEvaluators.get(0).ylabel(); // Vector<EvalCell> -> Vector<Pair> // Convert the set of alignments into the list of required point pairs // We must convert the Vector<Vector<Pair>> toplot = new Vector<Vector<Pair>>(); for (int i = 0; i < size; i++) { // Convert it with the adequate GraphPlotter // Scale the point pairs to the current display (local) toplot.add(i, listEvaluators.get(i).eval(parameters)); //scaleResults( STEP, } // Set output file OutputStream stream; if (outputfilename == null) { stream = System.out; } else { stream = new FileOutputStream(outputfilename); } PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream, "UTF-8")), true); //System.err.println ( toplot.get(0)); // Display the required type of output // Vector<Pair> -> . if (type.equals("tsv")) { printTSV(toplot, writer); } else if (type.equals("html")) { printHTMLGGraph(toplot, writer); } else if (type.equals("tex")) { printPGFTex(toplot, writer); } else { logger.error("Flag -t {} : not implemented yet", type); usage(); System.exit(-1); } }