List of usage examples for org.apache.commons.cli Option getValue
public String getValue()
null
if there is no value. From source file:org.scidb.iquery.Config.java
/** * Parse command-line parameters into the Config object. * * @note (For developers:) Please do not use a number as either a short option name or a long option name. * This will ensure that DefaultParser::isArgument() returns true if and only if the token is not an option. *//* ww w . j a va 2 s . c om*/ public void parse(String[] args) throws ParseException { Options options = new Options(); options.addOption(Option.builder("w").required(false).hasArg(true).longOpt("precision").build()); options.addOption(Option.builder("c").required(false).hasArg(true).longOpt("host").build()); options.addOption(Option.builder("p").required(false).hasArg(true).longOpt("port").build()); options.addOption(Option.builder("q").required(false).hasArg(true).longOpt("query").build()); options.addOption(Option.builder("f").required(false).hasArg(true).longOpt("query_file").build()); options.addOption(Option.builder("r").required(false).hasArg(true).longOpt("result").build()); options.addOption(Option.builder("o").required(false).hasArg(true).longOpt("format").build()); options.addOption(Option.builder("A").required(false).hasArg(true).longOpt("auth-file").build()); //options.addOption(Option.builder("U").required(false).hasArg(true).longOpt("user-name").build()); //options.addOption(Option.builder("P").required(false).hasArg(true).longOpt("user-password").build()); options.addOption(Option.builder("v").required(false).hasArg(false).longOpt("verbose").build()); options.addOption(Option.builder("t").required(false).hasArg(false).longOpt("timer").build()); options.addOption(Option.builder("n").required(false).hasArg(false).longOpt("no_fetch").build()); options.addOption(Option.builder("a").required(false).hasArg(false).longOpt("afl").build()); options.addOption(Option.builder("h").required(false).hasArg(false).longOpt("help").build()); options.addOption(Option.builder("V").required(false).hasArg(false).longOpt("version").build()); options.addOption(Option.builder("i").required(false).hasArg(false).longOpt("ignore_errors").build()); options.addOption( Option.builder("b").required(false).hasArg(false).longOpt("bypass_usr_cfg_perms_chk").build()); CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(options, args); Option[] processedOptions = line.getOptions(); for (Option o : processedOptions) { switch (o.getId()) { case 'w': setPrecision(Integer.parseInt(o.getValue())); break; case 'c': setHost(o.getValue()); break; case 'p': setPort(Integer.parseInt(o.getValue())); break; case 'q': setQuery(o.getValue()); break; case 'f': setQueryFile(o.getValue()); break; case 'r': setResult(o.getValue()); break; case 'o': setFormat(o.getValue()); break; case 'A': setAuthFile(o.getValue()); break; case 'v': setVerbose(true); break; case 't': setTimer(true); break; case 'n': setNoFetch(true); break; case 'a': setAfl(true); break; case 'i': setIgnoreErrors(true); break; case 'b': setBypassUsrCfgPermsChk(true); break; case 'h': printHelp(); System.exit(0); case 'V': printVersion(); System.exit(0); case '?': System.exit(1); } } }
From source file:org.seedstack.seed.shell.internal.AbstractShell.java
@SuppressWarnings("unchecked") protected Command createCommandAction(String qualifiedName, List<String> args) { if (Strings.isNullOrEmpty(qualifiedName)) { throw SeedException.createNew(ShellErrorCode.MISSING_COMMAND); }/* w w w. j a v a 2 s . c o m*/ String commandScope; String commandName; if (qualifiedName.contains(":")) { String[] splitName = qualifiedName.split(":"); commandScope = splitName[0].trim(); commandName = splitName[1].trim(); } else { commandScope = null; commandName = qualifiedName.trim(); } // Build CLI options Options options = new Options(); for (org.seedstack.seed.core.spi.command.Option option : commandRegistry.getOptionsInfo(commandScope, commandName)) { options.addOption(option.name(), option.longName(), option.hasArgument(), option.description()); } // Parse the command options CommandLine cmd; try { cmd = commandLineParser.parse(options, args.toArray(new String[args.size()])); } catch (ParseException e) { throw SeedException.wrap(e, ShellErrorCode.OPTIONS_SYNTAX_ERROR); } Map<String, String> optionValues = new HashMap<String, String>(); for (Option option : cmd.getOptions()) { optionValues.put(option.getOpt(), option.getValue()); } return commandRegistry.createCommand(commandScope, commandName, cmd.getArgList(), optionValues); }
From source file:org.seedstack.shell.internal.AbstractShell.java
@SuppressWarnings("unchecked") Command createCommandAction(String qualifiedName, List<String> args) { if (Strings.isNullOrEmpty(qualifiedName)) { throw SeedException.createNew(ShellErrorCode.MISSING_COMMAND); }/* w w w . j a v a2 s. com*/ String commandScope; String commandName; if (qualifiedName.contains(":")) { String[] splitName = qualifiedName.split(":"); commandScope = splitName[0].trim(); commandName = splitName[1].trim(); } else { commandScope = null; commandName = qualifiedName.trim(); } // Build CLI options Options options = new Options(); for (org.seedstack.seed.command.Option option : commandRegistry.getOptionsInfo(commandScope, commandName)) { options.addOption(option.name(), option.longName(), option.hasArgument(), option.description()); } // Parse the command options CommandLine cmd; try { cmd = commandLineParser.parse(options, args.toArray(new String[args.size()])); } catch (ParseException e) { throw SeedException.wrap(e, ShellErrorCode.OPTIONS_SYNTAX_ERROR); } Map<String, String> optionValues = new HashMap<>(); for (Option option : cmd.getOptions()) { optionValues.put(option.getOpt(), option.getValue()); } return commandRegistry.createCommand(commandScope, commandName, cmd.getArgList(), optionValues); }
From source file:org.stathissideris.ascii2image.core.CommandLineConverter.java
private static void printRunInfo(CommandLine cmdLine) { System.out.println("\n" + notice + "\n"); System.out.println("Running with options:"); Option[] opts = cmdLine.getOptions(); for (Option option : opts) { if (option.hasArgs()) { for (String value : option.getValues()) { System.out.println(option.getLongOpt() + " = " + value); }// w w w .j a v a 2 s . c o m } else if (option.hasArg()) { System.out.println(option.getLongOpt() + " = " + option.getValue()); } else { System.out.println(option.getLongOpt()); } } }
From source file:org.stathissideris.ascii2image.core.ConversionOptions.java
public ConversionOptions(CommandLine cmdLine) throws UnsupportedEncodingException { processingOptions.setVerbose(cmdLine.hasOption("verbose")); renderingOptions.setDropShadows(!cmdLine.hasOption("no-shadows")); this.setDebug(cmdLine.hasOption("debug")); processingOptions.setOverwriteFiles(cmdLine.hasOption("overwrite")); if (cmdLine.hasOption("scale")) { Float scale = Float.parseFloat(cmdLine.getOptionValue("scale")); renderingOptions.setScale(scale.floatValue()); }//from w w w. ja va 2 s .c o m processingOptions.setAllCornersAreRound(cmdLine.hasOption("round-corners")); processingOptions.setPerformSeparationOfCommonEdges(!cmdLine.hasOption("no-separation")); renderingOptions.setAntialias(!cmdLine.hasOption("no-antialias")); renderingOptions.setFixedSlope(cmdLine.hasOption("fixed-slope")); if (cmdLine.hasOption("background")) { String b = cmdLine.getOptionValue("background"); Color background = parseColor(b); renderingOptions.setBackgroundColor(background); } if (cmdLine.hasOption("transparent")) { renderingOptions.setBackgroundColor(new Color(0, 0, 0, 0)); } if (cmdLine.hasOption("tabs")) { Integer tabSize = Integer.parseInt(cmdLine.getOptionValue("tabs")); int tabSizeValue = tabSize.intValue(); if (tabSizeValue < 0) tabSizeValue = 0; processingOptions.setTabSize(tabSizeValue); } String encoding = (String) cmdLine.getOptionValue("encoding"); if (encoding != null) { new String(new byte[2], encoding); processingOptions.setCharacterEncoding(encoding); } ConfigurationParser configParser = new ConfigurationParser(); try { for (Option curOption : cmdLine.getOptions()) { if (curOption.getLongOpt().equals("config")) { String configFilename = curOption.getValue(); System.out.println("Parsing configuration file " + configFilename); File file = new File(configFilename); if (file.exists()) { configParser.parseFile(file); HashMap<String, CustomShapeDefinition> shapes = configParser.getShapeDefinitionsHash(); processingOptions.putAllInCustomShapes(shapes); } else { System.err.println("File " + file + " does not exist, skipping"); } } } } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.vpac.ndg.cli.Client.java
public Band parseBand(List<String> properties, String oldBandId) { Band band = sm.getBandConnector().retrieve(oldBandId); for (Option opt : cmd.getOptions()) { switch (opt.getLongOpt()) { case "name": band.setName(opt.getValue()); break; case "continuous": band.setContinuous(Boolean.parseBoolean(opt.getValue())); break; case "metadata": band.setMetadata(Boolean.parseBoolean(opt.getValue())); break; case "type": band.setType(RasterDetails.valueOf(opt.getValue())); break; }/* ww w .j a v a2s . c o m*/ } return band; }
From source file:org.vpac.ndg.cli.Client.java
public Dataset parseDataset(List<String> properties, String datasetId) throws java.text.ParseException { Dataset ds = sm.getDatasetConnector().get(datasetId); for (Option opt : cmd.getOptions()) { switch (opt.getLongOpt()) { case "abstract": ds.setAbst(opt.getValue()); break; case "name": ds.setName(opt.getValue());/*from w w w . ja va2 s . co m*/ break; } } return ds; }
From source file:org.vpac.ndg.cli.Client.java
public TimeSlice parseTimeslice(List<String> properties, String timesliceId) throws java.text.ParseException { TimeSlice ts = sm.getTimesliceConnector().get(timesliceId); for (Option opt : cmd.getOptions()) { switch (opt.getLongOpt()) { case "acquisitiontime": DateFormat formatter = Utils.getTimestampFormatter(); ts.setCreated(formatter.parse(opt.getValue())); break; case "abstract": ts.setDataAbstract(opt.getValue()); break; case "xmin": ts.setXmin(Double.parseDouble(opt.getValue())); break; case "xmax": ts.setXmax(Double.parseDouble(opt.getValue())); break; case "ymin": ts.setYmin(Double.parseDouble(opt.getValue())); break; case "ymax": ts.setYmax(Double.parseDouble(opt.getValue())); break; }/*from ww w.j a v a 2s .com*/ } return ts; }
From source file:org.wikidata.wdtk.client.ClientConfiguration.java
/** * Analyses the command-line arguments which are relevant for the specific * action that is to be executed, and returns a corresponding * {@link DumpProcessingAction} object.//from www . j a v a 2 s .co m * * @param cmd * {@link CommandLine} objects; contains the command line * arguments parsed by a {@link CommandLineParser} * @return {@link DumpProcessingAction} for the given arguments */ private DumpProcessingAction handleActionArguments(CommandLine cmd) { DumpProcessingAction result = makeDumpProcessingAction(cmd.getOptionValue(CMD_OPTION_ACTION).toLowerCase()); if (result == null) { return null; } for (Option option : cmd.getOptions()) { result.setOption(option.getLongOpt(), option.getValue()); } checkDuplicateStdOutOutput(result); return result; }
From source file:pl.nask.hsn2.GenericCmdParams.java
private void printOptions() { Option[] opts = cmd.getOptions(); for (Option op : opts) { LOGGER.info("Command line option: {}. Value from command line: {}, default value={}", new Object[] { op.getOpt(), op.getValue(), getDefaultValue(op.getOpt()) }); }//from www .j a v a2s. com }