List of usage examples for org.apache.commons.cli Option getLongOpt
public String getLongOpt()
From source file:org.rhq.server.metrics.migrator.DataMigratorRunner.java
/** * Print the options used to run the migration process *//*from ww w . java 2 s. c o m*/ private void printOptions() { log.debug("Running migration with the following optons: "); for (Entry<Object, Object> configOption : this.configuration.entrySet()) { Option option = (Option) configOption.getKey(); if (option.getLongOpt() != null && !option.getLongOpt().contains("pass")) { if (!(configOption.getValue() instanceof Object[])) { log.debug(" " + option.getLongOpt() + " : " + configOption.getValue()); } else { StringBuffer arrayProperty = new StringBuffer(); arrayProperty.append(" ").append(option.getLongOpt()).append(" : ["); boolean first = true; for (Object value : (Object[]) configOption.getValue()) { if (!first) { arrayProperty.append(", "); } arrayProperty.append(value); first = false; } arrayProperty.append("]"); log.debug(arrayProperty.toString()); } } else { log.debug(" " + option.getLongOpt() + " : <obscured value>"); } } }
From source file:org.rhq.storage.installer.StorageInstaller.java
private void checkPerms(Option option, String path, List<String> errors) { try {//from w ww. j av a 2 s . c om log.info("Checking perms for " + path); File dir = new File(path); if (!dir.isAbsolute()) { dir = new File(new File(storageBasedir, "bin"), path); } dir = dir.getCanonicalFile(); if (dir.exists()) { if (dir.isFile()) { errors.add(path + " is not a directory. Use the --" + option.getLongOpt() + " to change this value."); } } else { File parentDir = dir.getParentFile(); while (!parentDir.exists()) { parentDir = parentDir.getParentFile(); } if (!parentDir.canWrite()) { errors.add("The user running this installer does not appear to have write permissions to " + parentDir + ". Either make sure that the user running the storage node has write permissions or use the --" + option.getLongOpt() + " to change this value."); } } } catch (Exception e) { errors.add("The request path cannot be constructed (path: " + path + "). " + "Please use a valid and also make sure the user running the storage node has write permissions for the path."); } }
From source file:org.rhq.storage.installer.StorageInstaller.java
public Options getHelpOptions() { Options helpOptions = new Options(); for (Option option : (Collection<Option>) options.getOptions()) { if (option.getLongOpt().equals(StorageProperty.VERIFY_DATA_DIRS_EMPTY)) { continue; }//from www.j av a 2s. c o m helpOptions.addOption(option); } return helpOptions; }
From source file:org.sakuli.starter.SakuliStarter.java
private static String getOptionValue(CommandLine cmd, Option option) { return option.getOpt() != null ? cmd.getOptionValue(option.getOpt()) : cmd.getOptionValue(option.getLongOpt()); }
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); }//from ww w. j a v a 2 s .co 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 ww w . j av a 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.vetmeduni.tools.AbstractTool.java
/** * Get the arguments with the string/*ww w . j a va 2 s.c o m*/ * * @param cmd the already parsed command line with the programParser * * @return the string with the arguments in the command line properly formatted */ protected String getCmdLineString(CommandLine cmd) { StringBuilder builder = new StringBuilder(""); for (Option opt : cmd.getOptions()) { if (opt.hasArg()) { for (String val : opt.getValues()) { builder.append("--"); builder.append(opt.getLongOpt()); builder.append(" "); builder.append(val); builder.append(" "); } } else { builder.append("--"); builder.append(opt.getLongOpt()); builder.append(" "); } } return builder.toString(); }
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; }/* w ww.ja va 2s .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());//from w w w.j av a2 s .c om break; case "name": ds.setName(opt.getValue()); 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; }/* w w w .j a v a2 s. co m*/ } return ts; }