List of usage examples for org.apache.commons.cli Options getOptions
public Collection getOptions()
From source file:dk.hippogrif.prettyxml.app.Main.java
private static List sortOptions(Options options) { ArrayList list = new ArrayList(options.getOptions()); Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { return ((Option) o1).getOpt().compareTo(((Option) o2).getOpt()); }/*www. ja v a 2 s .c om*/ }); return list; }
From source file:com.xtructure.xutil.opt.XOption.java
/** * Parses the given args array with the given parser, passing the arguments * to the given options//ww w. j a va2s . co m * * @param options * @param args * @param parser * @throws ParseException */ public static final void parseArgs(Options options, String[] args, Parser parser) throws ParseException { CommandLine cl = parser.parse(options, args); for (Object obj : options.getOptions()) { if (obj instanceof XOption<?>) { XOption<?> xOption = (XOption<?>) obj; xOption.setHasValue(cl.hasOption(xOption.getOpt())); } } }
From source file:io.stpettersen.bluejpackager.BlueJPackager.java
private static void displayUsage(Options options, int exitCode) { System.out.println("\nBlueJ Packager."); System.out.println("Utility to morph a BlueJ project into a structured Java package."); System.out.println("\nCopyright (c) 2016 Sam Saint-Pettersen."); System.out.println("Released under the MIT License.\n"); for (Option opt : options.getOptions()) { String[] fopt = opt.toString().split("::", 3); System.out.println(fopt[0].replace("[ option: ", "-") + ":" + fopt[1]); }/* w w w. ja v a 2 s . c o m*/ System.out.println(""); System.exit(exitCode); }
From source file:backtype.storm.GenericOptionsParser.java
static Options buildGeneralOptions(Options opts) { Options r = new Options(); for (Object o : opts.getOptions()) r.addOption((Option) o);// w w w. j a v a 2s.c o m Option libjars = OptionBuilder.withArgName("paths").hasArg() .withDescription("comma separated jars to be used by the submitted topology").create("libjars"); r.addOption(libjars); optionProcessors.put("libjars", new LibjarsProcessor()); Option conf = OptionBuilder.withArgName("configuration file").hasArg() .withDescription("an application configuration file").create("conf"); r.addOption(conf); optionProcessors.put("conf", new ConfFileProcessor()); // Must come after `conf': this option is of higher priority Option extraConfig = OptionBuilder.withArgName("D").hasArg() .withDescription("extra configurations (preserving types)").create("D"); r.addOption(extraConfig); optionProcessors.put("D", new ExtraConfigProcessor()); return r; }
From source file:com.picocontainer.script.Standalone.java
private static void printUsage(final Options options) { final String lineSeparator = System.getProperty("line.separator"); final StringBuffer usage = new StringBuffer(); usage.append(lineSeparator);/*from ww w . j av a 2 s . c o m*/ usage.append("PicoContainer Standalone: -c <composition-file> [-q|-n|-h|-v]"); usage.append(options.getOptions()); System.out.println(usage.toString()); }
From source file:net.sf.jvifm.util.AutoCompleteUtil.java
@SuppressWarnings("all") public static String getCommandOptionTip(String cmd) { Options options = CommandRegister.getInstance().getCommandOptions(cmd); if (options == null) return null; Collection ops = options.getOptions(); StringBuffer sb = new StringBuffer(); for (Iterator it = ops.iterator(); it.hasNext();) { String opt = ((Option) it.next()).getOpt(); sb.append("-").append(opt).append(" "); }//from ww w . j a v a2 s .c o m return sb.toString(); }
From source file:EditBinFile.java
private static void printHelp(Options options) { Collection list = options.getOptions(); Iterator iterator = list.iterator(); // while loop String tmp = ""; Option otmp;//from w ww.ja v a2s .c o m while (iterator.hasNext()) { otmp = (Option) iterator.next(); System.out.println(String.format("%-15s %s", "-" + otmp.getOpt(), otmp.getDescription())); } }
From source file:com.basistech.lucene.tools.LuceneQueryTool.java
private static void validateOptions(Options options, String[] args) throws org.apache.commons.cli.ParseException { Set<String> optionNames = Sets.newHashSet(); // non-generic forced by commons.cli api for (Object o : options.getOptions()) { Option option = (Option) o; optionNames.add(option.getLongOpt()); String shortOpt = option.getOpt(); if (shortOpt != null) { optionNames.add(shortOpt);//from w w w .j a v a 2 s . c o m } } for (String arg : args) { if (arg.startsWith("-")) { String argName = arg.replaceFirst("-+", ""); if (!optionNames.contains(argName)) { throw new org.apache.commons.cli.ParseException("Unrecognized option: " + arg); } } } }
From source file:com.rabbitmq.client.test.performance.CLIHelper.java
public CLIHelper(Options opts) { Iterator<?> it = opts.getOptions().iterator(); while (it.hasNext()) { options.addOption((Option) it.next()); }/*from w w w . java 2 s. c o m*/ }
From source file:com.garethahealy.fuse.aries.transactions.cli.parsers.DefaultCLIParser.java
public CommandLine parse(String[] args, Options options) throws ParseException { if (options == null || options.getOptions() == null || options.getOptions().size() <= 0) { throw new ParseException("Provided options is null or empty"); }/*from w w w. j a v a 2 s . c o m*/ if (args == null || args.length <= 0) { throw new ParseException("Provided args is null or empty"); } return parser.parse(options, args, true); }