List of usage examples for org.apache.commons.cli2 Option getPreferredName
String getPreferredName();
From source file:com.gsinnovations.howdah.AbstractJob.java
protected static void maybePut(Map<String, String> args, CommandLine cmdLine, Option... opt) { for (Option o : opt) { // the option appeared on the command-line, or it has a value // (which is likely a default value). if (cmdLine.hasOption(o) || cmdLine.getValue(o) != null) { // nulls are ok, for cases where options are simple flags. Object vo = cmdLine.getValue(o); String value = (vo == null) ? null : vo.toString(); args.put(o.getPreferredName(), value); }//from w w w . j av a 2s .com } }
From source file:my.mahout.AbstractJob.java
protected static void maybePut(Map<String, List<String>> args, CommandLine cmdLine, Option... opt) { for (Option o : opt) { // the option appeared on the command-line, or it has a value // (which is likely a default value). if (cmdLine.hasOption(o) || cmdLine.getValue(o) != null || (cmdLine.getValues(o) != null && !cmdLine.getValues(o).isEmpty())) { // nulls are ok, for cases where options are simple flags. List<?> vo = cmdLine.getValues(o); if (vo != null && !vo.isEmpty()) { List<String> vals = Lists.newArrayList(); for (Object o1 : vo) { vals.add(o1.toString()); }//from w w w. j a v a 2 s . c om args.put(o.getPreferredName(), vals); } else { args.put(o.getPreferredName(), null); } } } }
From source file:my.mahout.AbstractJob.java
/** * @param name The name of the option//w w w.j av a2 s . co m * @return the {@link org.apache.commons.cli2.Option} with the name, else null */ protected Option getCLIOption(String name) { for (Option option : options) { if (option.getPreferredName().equals(name)) { return option; } } return null; }
From source file:com.ibm.jaql.util.shell.JaqlShellArguments.java
@SuppressWarnings("unchecked") static JaqlShellArguments parseArgs(String... args) { // option builders final DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); final ArgumentBuilder abuilder = new ArgumentBuilder(); final GroupBuilder gbuilder = new GroupBuilder(); // create standard options Option optHelp = obuilder.withShortName("h").withShortName("?").withLongName("help") .withDescription("print this message").create(); Option optJars = obuilder.withShortName("j").withLongName("jars") .withDescription(/*from ww w . j a v a 2 s. c o m*/ "comma-separated list of jar files to include user defined expressions or data stores") .withArgument(abuilder.withName("args").withMinimum(1).withMaximum(1).create()).create(); Option optSearchPath = obuilder.withShortName("jp").withLongName("jaql-path") .withDescription("colon seperated list of all search path entries") .withArgument(abuilder.withName("args").withMinimum(1).withMaximum(1).create()).create(); Option optBatch = obuilder.withShortName("b").withLongName("batch") .withDescription("run in batch mode (i.e., do not read from stdin)").create(); Option optOutOptions = obuilder.withShortName("o").withLongName("outoptions") .withDescription("output options: json, del and xml or an output IO descriptor. " + "This option is ignored when not running in batch mode.") .withArgument(abuilder.withName("outoptions").withMinimum(1).withMaximum(1).create()).create(); Option optEval = obuilder.withShortName("e").withLongName("eval") .withDescription("evaluate Jaql expression") .withArgument(abuilder.withName("expr").withMinimum(1).withMaximum(1).create()).create(); // create mini-cluster options Option optCluster = obuilder.withShortName("c").withLongName("cluster") .withDescription("use existing cluster (i.e., do not launch a mini-cluster)").create(); Option optNumNodes = obuilder.withShortName("n").withLongName("no-nodes") .withDescription("mini-cluster option: number of nodes to spawn") .withArgument(abuilder.withName("arg").withMinimum(1).withMaximum(1) .withValidator(NumberValidator.getIntegerInstance()).create()) .create(); Option optDir = obuilder.withShortName("d").withLongName("hdfs-dir") .withDescription("mini-cluster option: root HDFs directory") .withArgument(abuilder.withName("arg").withMinimum(1).withMaximum(1).create()).create(); Group clusterOptions = gbuilder.withName("Cluster options").withOption(optCluster).withOption(optDir) .withOption(optNumNodes).create(); // create input files option Option optInputFiles = abuilder.withName("file").withDescription("list of input files").withMinimum(0) .create(); Option optLog = obuilder.withShortName("l").withLongName("log") .withDescription("log options: json, del and xml or an output IO descriptor. ") .withArgument(abuilder.withName("arg").withMinimum(1).withMaximum(1).create()).create(); // combine all options Group options = gbuilder.withName("options").withOption(optHelp).withOption(optJars) .withOption(optSearchPath).withOption(optBatch).withOption(optLog).withOption(optOutOptions) .withOption(optEval).withOption(optInputFiles).withOption(clusterOptions).create(); // parse and print help if necessary CommandLine cl; try { Parser parser = new Parser(); parser.setGroup(options); cl = parser.parse(args); } catch (OptionException e) { printHelpAndExit(e, null, options); return null; } if (cl.hasOption(optHelp)) { printHelpAndExit(null, options); } // validate arguments JaqlShellArguments result = new JaqlShellArguments(); // mini-cluster options if (cl.hasOption(optCluster)) { result.useExistingCluster = true; } if (cl.hasOption(optDir)) { if (result.useExistingCluster) { printHelpAndExit("Options " + optCluster.getPreferredName() + " and " + optDir.getPreferredName() + " are mutually exclusive", options); } result.hdfsDir = (String) cl.getValue(optDir); } if (cl.hasOption(optNumNodes)) { if (result.useExistingCluster) { printHelpAndExit("Options " + optCluster.getPreferredName() + " and " + optNumNodes.getPreferredName() + " are mutually exclusive", options); } result.numNodes = ((Number) cl.getValue(optNumNodes)).intValue(); } // jar files if (cl.hasOption(optJars)) { result.jars = ((String) cl.getValue(optJars)).split(","); for (String jar : result.jars) { if (!new File(jar).exists()) { printHelpAndExit("Jar file " + jar + " not found", options); } } } // search path directories if (cl.hasOption(optSearchPath)) { result.searchPath = ((String) cl.getValue(optSearchPath)).split(":"); for (String dir : result.searchPath) { if (!new File(dir).exists() || !new File(dir).isDirectory()) { printHelpAndExit("Search-path entry " + dir + " not found or is no directory", options); } } } if (cl.hasOption(optBatch)) { result.batchMode = true; if (cl.hasOption(optOutOptions)) { String format = (String) cl.getValue(optOutOptions); try { result.outputAdapter = getOutputAdapter(format); } catch (Exception e) { printHelpAndExit(e, "\"" + format + "\" is neither a valid output format nor a valid IO descriptor", options); } } } // input if (cl.hasOption(optEval)) { String eval = (String) cl.getValue(optEval); if (!eval.endsWith(";")) eval += ";"; result.addInputStream(new ByteArrayInputStream(eval.getBytes())); } if (cl.hasOption(optInputFiles)) { List<String> files = (List<String>) cl.getValues(optInputFiles); for (String file : files) { try { result.addInputStream(new FileInputStream(file)); } catch (FileNotFoundException e) { printHelpAndExit(e, "Input file " + file + " not found", options); } } } // error log if (cl.hasOption(optLog)) { String path = (String) cl.getValue(optLog); try { BufferedJsonRecord logFD = new BufferedJsonRecord(); logFD.add(Adapter.TYPE_NAME, new JsonString("local")); logFD.add(Adapter.LOCATION_NAME, new JsonString(path)); OutputAdapter oa = (OutputAdapter) JaqlUtil.getAdapterStore().output.getAdapter(logFD); result.logAdapter = oa; } catch (Exception e) { printHelpAndExit(e, "\"" + path + "\" invalid", options); } } if (!result.batchMode) { result.addStdin(); } return result; }
From source file:org.opencloudengine.flamingo.mapreduce.core.AbstractJob.java
protected static void maybePut(Map<String, String> args, CommandLine cmdLine, Option... opt) { for (Option o : opt) { // ??? ? ? ? if (cmdLine.hasOption(o) || cmdLine.getValue(o) != null) { // ??? ? ? OK // nulls are ok, for cases where options are simple flags. Object vo = cmdLine.getValue(o); String value = vo == null ? null : vo.toString(); args.put(o.getPreferredName(), value); }//from ww w.ja v a 2 s . c om } }
From source file:org.rzo.yajsw.WrapperExe.java
/** * Execute command.// w w w. j ava 2s .c o m * * @param cmd * the cmd */ private static void executeCommand(Option cmd) { switch (cmd.getId()) { case OPTION_C: doConsole(); break; case OPTION_T: doStart(); break; case OPTION_P: doStop(); break; case OPTION_TX: doStartPosix(); break; case OPTION_PX: doStopPosix(); break; case OPTION_I: doInstall(); break; case OPTION_R: doRemove(); break; case OPTION_N: pid = ((Long) cl.getValue(cmd)).intValue(); doReconnect(); break; case OPTION_G: pid = ((Long) cl.getValue(cmd)).intValue(); doGenerate(); break; case OPTION_D: break; case OPTION_Q: doState(); break; case OPTION_QS: doStateSilent(); break; case OPTION_Y: doStartTrayIcon(); break; default: System.out.println("unimplemented option " + cmd.getPreferredName()); } }