List of usage examples for org.apache.commons.cli Option getOpt
public String getOpt()
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(// w w w . j a v a2 s . com String.format(" -%s|--%-30s ", opt.getOpt(), opt.getLongOpt()) + opt.getDescription()); } System.exit(0); }
From source file:com.lcdfx.pipoint.PiPoint.java
public PiPoint(String[] args) { this.addWindowListener(new WindowAdapter() { @Override/*from w w w .j a v a 2 s .co m*/ public void windowClosing(WindowEvent ev) { shutDown(); } }); // add logging logger = Logger.getLogger(this.getClass().getName()); logger.log(Level.INFO, "PiPoint version " + PiPoint.class.getPackage().getImplementationVersion() + " running under " + System.getProperty("java.vm.name") + " v" + System.getProperty("java.vm.version")); // get command line options CommandLineParser parser = new BasicParser(); Map<String, String> cmdOptions = new HashMap<String, String>(); Options options = new Options(); options.addOption(new Option("f", "fullscreen", false, "fullscreen mode (no cursor)")); CommandLine cmd = null; try { cmd = parser.parse(options, args); for (Option option : cmd.getOptions()) { cmdOptions.put(option.getOpt(), option.getValue()); } } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar pipoint.jar", options); System.exit(0); } if (cmd.hasOption("f")) { setUndecorated(true); BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor"); getContentPane().setCursor(blankCursor); } // instantiate the RendererManager mgr = new DlnaRendererManager(this); mgr.refreshDevices(); nowPlayingPanel = new NowPlayingPanel(this); mgr.getRenderer().addListener(nowPlayingPanel); devicePanel = new DevicePanel(this); this.getContentPane().setPreferredSize(new Dimension(DISPLAY_WIDTH, DISPLAY_HEIGHT)); this.getContentPane().add(devicePanel); }
From source file:de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.CommandFormatter.java
/** * Representates the command object as text with all options. The returned * string is formatted for console output. * * @return Command representation.//from ww w . j a va 2s .c o m */ @Override public String toString() { final String desc_sep = "\t\t"; final String desc_sep_break = "\n" + desc_sep; final String desc_opt_sep_break = desc_sep_break + "\t\t\t"; final Integer maxStrL = 100; final String cmdDescription = trimByWhitespace(cmd.getDescription(), desc_sep_break, maxStrL); StringBuilder strBuilder = new StringBuilder(cmd.getCommandName()).append(desc_sep).append(cmdDescription); if (cmd.getOptions().getOptions().size() > 0) { strBuilder.append("\n\n").append(desc_sep).append("Options:").append(desc_sep); } for (final Object o : cmd.getOptions().getOptions()) { if (o instanceof Option) { final Option opt = (Option) o; final String optName = opt.getOpt(); strBuilder.append("\n").append(desc_sep).append(optList(opt)); if (opt.hasArg()) { strBuilder.append(decorateArg(opt)); } final String optDescription = trimByWhitespace(opt.getDescription(), desc_opt_sep_break, maxStrL - optName.length() - 5); strBuilder.append(" : ").append(optDescription); } } return strBuilder.append("\n").toString(); }
From source file:gobblin.runtime.cli.ConstructorAndPublicMethodsCliObjectFactory.java
/** * Builds an instance of T using the selected constructor getting the constructor * parameters from the {@link CommandLine}. * * Note: this method will also automatically call {@link #applyCommandLineOptions(CommandLine, T)} on * the constructed object.//from www . ja va 2s. c o m */ private T buildInstance(CommandLine cli) { String[] constructorArgs = new String[this.constructor.getParameterTypes().length]; for (Option option : cli.getOptions()) { if (this.constructoArgumentsMap.containsKey(option.getOpt())) { int idx = this.constructoArgumentsMap.get(option.getOpt()); constructorArgs[idx] = option.getValue(); } } T embeddedGobblin; try { embeddedGobblin = this.constructor.newInstance((Object[]) constructorArgs); return embeddedGobblin; } catch (IllegalAccessException | InvocationTargetException | InstantiationException exc) { throw new RuntimeException("Could not instantiate " + this.klazz.getName(), exc); } }
From source file:edu.odu.cs.cs350.yellow1.ui.cli.ClI.java
/** * Process the arguments received from the user * If the required arguments are not received throws an exception<br> with a message containing the list of argument not received * @throws RequireArgumentsNotRecieved //from www . j ava 2 s .co m */ public void parse() throws RequireArgumentsNotRecieved { clp = new BasicParser(); try { cmd = clp.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp( "-src [SOURCE FOLDER] -mutF [SOURCE FILE] -testSte [TEST SUITE PATH] -goldOut [GOLD VERSION OUTPUT]", options); System.out.println( "To read output log: [Changed File] ,, [Start Index] ,, [Stop Index] ,, [Original Token] ,, [Mutated Token] ;;"); System.exit(0); } else { for (Option option : cmd.getOptions()) { System.out.println(option.getOpt() + " " + option.getValue()); recievedArgutments.put(option.getOpt(), option.getValue()); } } for (String key : recievedArgutments.keySet()) { if (requiredArgs.contains(key)) { requiredArgs.remove(key); } } if (!requiredArgs.isEmpty()) { throw new RequireArgumentsNotRecieved( "The required arguments: " + requiredArgs.toString() + " were not recieved"); } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:gobblin.runtime.cli.ConstructorAndPublicMethodsGobblinCliFactory.java
/** * Builds an instance of {@link EmbeddedGobblin} using the selected constructor getting the constructor * parameters from the {@link CommandLine}. * * Note: this method will also automatically call {@link #applyCommandLineOptions(CommandLine, EmbeddedGobblin)} on * the constructed {@link EmbeddedGobblin}. *///from w w w.ja v a 2 s .c o m public EmbeddedGobblin buildInstance(CommandLine cli) { String[] constructorArgs = new String[this.constructor.getParameterTypes().length]; for (Option option : cli.getOptions()) { if (this.constructoArgumentsMap.containsKey(option.getOpt())) { int idx = this.constructoArgumentsMap.get(option.getOpt()); constructorArgs[idx] = option.getValue(); } } EmbeddedGobblin embeddedGobblin; try { embeddedGobblin = this.constructor.newInstance((Object[]) constructorArgs); return embeddedGobblin; } catch (IllegalAccessException | InvocationTargetException | InstantiationException exc) { throw new RuntimeException("Could not instantiate " + this.klazz.getName(), exc); } }
From source file:kieker.tools.util.CLIHelpFormatter.java
@SuppressWarnings("unchecked") @Override//from w w w. ja v a2 s. c om protected StringBuffer renderOptions(final StringBuffer sb, final int width, final Options options, final int leftPad, final int descPad) { final String lpad = this.createPadding(leftPad); final String dpad = this.createPadding(8); // we use a fixed value instead of descPad StringBuilder optBuf; final List<Option> optList = new ArrayList<Option>(options.getOptions()); Collections.sort(optList, this.getOptionComparator()); for (final Iterator<Option> i = optList.iterator(); i.hasNext();) { final Option option = i.next(); optBuf = new StringBuilder(8); if (option.getOpt() == null) { optBuf.append(lpad).append(" ").append(this.getLongOptPrefix()).append(option.getLongOpt()); } else { optBuf.append(lpad).append(this.getOptPrefix()).append(option.getOpt()); if (option.hasLongOpt()) { optBuf.append(',').append(this.getLongOptPrefix()).append(option.getLongOpt()); } } if (option.hasArg()) { if (option.hasArgName()) { optBuf.append(" <").append(option.getArgName()).append('>'); } else { optBuf.append(' '); } } sb.append(optBuf.toString()).append(this.getNewLine()); optBuf = new StringBuilder(); optBuf.append(dpad); if (option.getDescription() != null) { optBuf.append(option.getDescription()); } this.renderWrappedText(sb, width, dpad.length(), optBuf.toString()); if (i.hasNext()) { sb.append(this.getNewLine()); sb.append(this.getNewLine()); } } return sb; }
From source file:com.somerledsolutions.pa11y.client.cli.OptionsBuilderTest.java
private void assertHelpOption(Options options) { Option helpOption = options.getOption("h"); assertEquals("h", helpOption.getOpt()); assertEquals("Help", helpOption.getArgName()); assertEquals("help", helpOption.getLongOpt()); assertEquals("Shows this help", helpOption.getDescription()); }
From source file:com.linkedin.databus2.core.schema.tools.AvroConvertMain.java
public int getVerbosity() { int cnt = 0;// www.j ava2s.c o m for (Option o : _cmdLine.getOptions()) if (o.getOpt().equals("v")) ++cnt; return cnt; }
From source file:com.somerledsolutions.pa11y.client.cli.OptionsBuilderTest.java
private void assertCreateOption(Options options) { Option createOption = options.getOption("c"); assertEquals("c", createOption.getOpt()); assertEquals("Create task", createOption.getArgName()); assertEquals("create", createOption.getLongOpt()); assertEquals("Create a new task", createOption.getDescription()); }