List of usage examples for org.apache.commons.cli Option getLongOpt
public String getLongOpt()
From source file:com.comcast.cats.vision.panel.remote.RemoteApplication.java
public void parseCommandLineArgs(String[] args) { String arg;//from w w w.j av a 2 s .c om Options options = new Options(); options.addOption("s", "server", true, "CATS server URL"); options.addOption("i", "irPath", true, "IR path off settop"); options.addOption("k", "keyset", true, "key set"); CommandLineParser parser = new PosixParser(); try { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Command Line Arguments", options); CommandLine cmd = parser.parse(options, args); for (Option opt : cmd.getOptions()) { switch (opt.getLongOpt()) { case "server": arg = opt.getValue(); logger.debug("Found mac address: " + arg); server = arg; break; case "irPath": arg = opt.getValue(); logger.debug("Found Server address: " + arg); irPath = arg; break; case "keyset": arg = opt.getValue(); logger.debug("Found login endpoint address: " + arg); keySet = arg; break; default: arg = opt.getValue(); logger.debug("Argument not found..." + arg); } } } catch (ParseException e) { logger.error("Command line argument parsing error"); e.printStackTrace(); } }
From source file:net.sourceforge.metware.binche.execs.CommandLineMain.java
@SuppressWarnings("unchecked") public void printHelp() { for (Object obj : options.getOptions().toArray(new Option[0])) { Option opt = (Option) obj; System.out.println(//www. jav a2 s. c om String.format(" -%s|--%-30s ", opt.getOpt(), opt.getLongOpt()) + opt.getDescription()); } System.exit(0); }
From source file:io.github.azagniotov.stubby4j.cli.CommandLineInterpreter.java
/** * Identifies what command line arguments that have been passed by user are matching available options * * @return a map of passed command line arguments where key is the name of the argument *///from ww w . j a va2 s . com @SuppressWarnings("unchecked") public Map<String, String> getCommandlineParams() { final Option[] options = line.getOptions(); return new HashMap<String, String>() { { for (final Option option : options) { put(option.getLongOpt(), option.getValue()); } PROVIDED_OPTIONS.addAll(new LinkedList(this.entrySet())); } }; }
From source file:com.github.horrorho.inflatabledonkey.args.ArgsManager.java
String parse(Option option, UnaryOperator<String> parser) { if (option.hasArgs()) { return option.getValuesList().stream().map(u -> parse(option.getLongOpt(), u, parser)) .collect(Collectors.joining(" ")); }// w w w . java 2 s. c o m if (option.hasArg()) { return parse(option.getLongOpt(), option.getValue(), parser); } return Boolean.TRUE.toString(); }
From source file:com.github.horrorho.liquiddonkey.settings.commandline.CommandLineOptions.java
public String opt(Option option) { return option.hasLongOpt() ? option.getLongOpt() : option.getOpt(); }
From source file:info.fetter.rrdclient.GraphCommand.java
/** * Create a wrapper object for the RRD graph command. * //from w w w . j ava2s.co m * @param args */ public GraphCommand(String... args) { try { this.args = args; CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("a", "imgformat", true, "image format"); options.addOption("s", "start", true, "start (default end-1day)"); options.addOption("e", "end", true, "end (default now)"); options.addOption("t", "title", true, "graph title"); options.addOption("n", "font", true, "font"); options.addOption("w", "width", true, "image width"); options.addOption("h", "height", true, "image height"); options.addOption("b", "base", true, "base value"); options.addOption("A", "alt-autoscale", false, "alternate scale algorithm"); options.addOption("M", "alt-autoscale-max", false, "alternate scale algorithm (max value only)"); options.addOption("J", "alt-autoscale-min", false, "alternate scale algorithm (min value only)"); options.addOption("l", "lower-limit", true, "lower limit"); options.addOption("u", "upper-limit", true, "upper limit"); options.addOption("r", "rigid", false, "rigid boundaries"); options.addOption("v", "vertical-label", true, "vertical label"); options.addOption("E", "slope-mode", false, "enable slope mode"); options.addOption("i", "interlaced", false, "interlaced image"); options.addOption("o", "logarithmic", false, "logarithmic scale"); options.addOption("z", "units", true, "use SI notation for logarithmic scale"); options.addOption("y", "y-grid", true, "Y grid step"); options.addOption("X", "units-exponent", true, "sets the 10**exponent scaling of the y-axis values"); CommandLine cmd = parser.parse(options, args, false); for (Option option : cmd.getOptions()) { logger.trace("Parsed option : " + option.getLongOpt()); } for (String arg : cmd.getArgs()) { logger.trace("Remaining arg : " + arg); } } catch (ParseException e) { throw new IllegalArgumentException(e); } }
From source file:com.cloudera.csd.tools.MetricToolsTest.java
@Test public void testRequiredOptions() { // Test that the only required metric options are metric tools options. Options options = new Options(); options.addOption(MetricTools.OPT_TOOL); for (Option option : MetricTools.OPTIONS.getOptions()) { if (option.isRequired()) { Assert.assertTrue("Required option not allowed in specific tools", options.hasLongOption(option.getLongOpt())); }/* w w w . j av a2s . c o m*/ } }
From source file:de.yaio.commons.config.Configuration.java
public void putCliOptions(org.apache.commons.cli.Option[] cliOptions) { for (final org.apache.commons.cli.Option prop : Arrays.asList(cliOptions)) { if (!StringUtils.isEmpty(prop.getLongOpt())) { this.putCliOption(new ConfigurationOption(prop.getLongOpt(), prop.getValue())); }//from ww w. j a v a 2 s.co m if (!StringUtils.isEmpty(prop.getOpt())) { this.putCliOption(new ConfigurationOption(prop.getOpt(), prop.getValue())); } } }
From source file:com.teradata.tempto.runner.TemptoRunnerCommandLineParser.java
private Optional<String> getOptionValue(CommandLine commandLine, Option option) { String longOpt = option.getLongOpt(); if (defaults.containsKey(longOpt)) { return Optional.of(commandLine.getOptionValue(longOpt, defaults.get(longOpt).getValue())); }// w w w. j a va2s . co m Optional<String> value = Optional.ofNullable(commandLine.getOptionValue(longOpt)); if (!value.isPresent() && commandLine.hasOption(longOpt)) { return Optional.of(TRUE.toString()); } return value; }
From source file:main.CommandLineParser.java
private boolean hasOption(CommandLine cmd, Option option) { String name = option.getLongOpt(); assert (name != null); return cmd.hasOption(name); }