| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (1.8.0_181) on Fri Sep 14 11:35:59 BST 2018 --> |
| <title>Overview (Command Line Parsing API)</title> |
| <meta name="date" content="2018-09-14"> |
| <link rel="stylesheet" type="text/css" href="javadoc.css" title="Style"> |
| <script type="text/javascript" src="script.js"></script> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| try { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="Overview (Command Line Parsing API)"; |
| } |
| } |
| catch(err) { |
| } |
| //--> |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a name="navbar.top"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> |
| <a name="navbar.top.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li class="navBarCell1Rev">Overview</li> |
| <li>Package</li> |
| <li>Class</li> |
| <li>Use</li> |
| <li><a href="overview-tree.html">Tree</a></li> |
| <li><a href="deprecated-list.html">Deprecated</a></li> |
| <li><a href="index-files/index-1.html">Index</a></li> |
| <li><a href="help-doc.html">Help</a></li> |
| </ul> |
| <div class="aboutLanguage">org.netbeans.modules.sendopts/2 2.38.1 </div> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li>Prev</li> |
| <li>Next</li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="index.html?overview-summary.html" target="_top">Frames</a></li> |
| <li><a href="overview-summary.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_top"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <a name="skip.navbar.top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| <div class="header"> |
| <h1 class="title">Command Line Parsing API<br/><span style='font-style:normal; font-size:medium; font-weight:normal; background-color:#ffffff;'><a href='http://wiki.netbeans.org/API_Stability#Official' target='_blank'>Official</a></span></h1> |
| </div> |
| <div class="header"> |
| <p>See: <a href="#overview.description">Description</a></p> |
| </div> |
| <div class="contentContainer"> |
| <table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Command Line Parsing API table, listing packages, and an explanation"> |
| <caption><span>Command Line Parsing API</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Package</th> |
| <th class="colLast" scope="col">Description</th> |
| </tr> |
| <tbody> |
| <tr class="altColor"> |
| <td class="colFirst"><a href="org/netbeans/api/sendopts/package-summary.html">org.netbeans.api.sendopts</a></td> |
| <td class="colLast"> |
| <div class="block">Start here if you are in a standalone application and you want to |
| parse a <a href="./org/netbeans/api/sendopts/CommandLine.html">command line</a> using the <code>sendopts</code> infrastructure.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><a href="org/netbeans/spi/sendopts/package-summary.html">org.netbeans.spi.sendopts</a></td> |
| <td class="colLast"> |
| <div class="block">Package for those that want to write a |
| <a href="./org/netbeans/spi/sendopts/Arg.html">command line handler</a> |
| that can participate on handling parts of a |
| command line send to the application.</div> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="contentContainer"><a name="overview.description"> |
| <!-- --> |
| </a> |
| <div class="block"><p> |
| |
| <p> |
| |
| <a href="org/netbeans/api/sendopts/package-summary.html">SendOptsAPI</a> |
| allows anyone to parse an array of strings - e.g. a command line. |
| The infrastracture of the module then locates all providers |
| registered using the |
| <a href="org/netbeans/spi/sendopts/package-summary.html">SendOptsSPI</a> |
| and distributes the parts of the command line to their handlers. |
| It is expected that the handlers do not know about each |
| other and are in fact provided by different modules. The goal of the sendopts |
| framework |
| is to get the description of the handlers, apply the gained knowledge to |
| the actual content of the command line and distribute the parts of the |
| command line arguments to the designated handlers. Beyond this optimal |
| state the error handling and help composition is also supported by this |
| infrastructure. |
| </p> |
| |
| |
| </p> |
| <h3>What is New (see <a href="apichanges.html">all changes</a>)?</h3> |
| <ul> |
| |
| |
| <!--Search for dates that are later or equal to 1997-09-01 in |
| .--> |
| <!--Checking date 2017-3-23 with count of newer 0--><!--year ok--> |
| <li>Mar 23 '17 <a href="apichanges.html#instances">Command line with instances</a> |
| <p> |
| |
| <a href="org/netbeans/api/sendopts/CommandLine.html#create-java.lang.Object...-" shape="rect">Create</a> |
| command line with instances of |
| <a href="org/netbeans/spi/sendopts/OptionProcessor.html" shape="rect">OptionProcessor</a> |
| and |
| <a href="org/netbeans/spi/sendopts/ArgsProcessor.html" shape="rect">ArgsProcessor</a>. |
| </p> |
| </li> |
| <!--Checking date 2017-3-21 with count of newer 1--><!--year ok--> |
| <li>Mar 21 '17 <a href="apichanges.html#usage-into">Print Usage into Caller's Stream</a> |
| <p> |
| |
| <a href="org/netbeans/spi/sendopts/Env.html#usage-java.io.OutputStream-" shape="rect">Env.usage</a> |
| method now takes an optional <code>OutputStream</code> parameter. |
| </p> |
| </li> |
| <!--Checking date 2017-3-21 with count of newer 1--><!--year ok--> |
| <li>Mar 21 '17 <a href="apichanges.html#explicit-options-processor">Explictly specify option processors</a> |
| <p> |
| |
| <a href="org/netbeans/api/sendopts/CommandLine.html#create-java.lang.Class...-" shape="rect">CommandLine.html.create(Class...)</a> |
| can now be called with classes that extend |
| <a href="org/netbeans/spi/sendopts/OptionProcessor.html" shape="rect">OptionProcessor</a>. |
| </p> |
| </li> |
| <!--Checking date 2012-3-18 with count of newer 3--><!--year ok--> |
| <li>Mar 18 '12 <a href="apichanges.html#own-hep">Easier way to process own <code>--help</code> request</a> |
| <p> |
| |
| <a href="org/netbeans/spi/sendopts/Env.html#usage--" shape="rect">Env.usage</a> |
| can be called when one wants to process own <code>--help</code> option. |
| </p> |
| </li> |
| <!--Checking date 2011-12-31 with count of newer 4--><!--year ok--> |
| <li>Dec 31 '11 <a href="apichanges.html#declarative-options">@Arg annotation</a> |
| <p> |
| |
| <a href="org/netbeans/spi/sendopts/Arg.html" shape="rect">@Arg</a> annotation |
| and associated classes allow to register options declaratively. There |
| is a new <a href="org/netbeans/api/sendopts/CommandLine.html#create-java.lang.Class...-" shape="rect"> |
| factory method |
| </a> to create multiple instances of differently configured |
| <a href="org/netbeans/api/sendopts/CommandLine.html" shape="rect">command lines</a>. |
| </p> |
| </li> |
| <!--Checking date 2007-7-30 with count of newer 5--><!--Skipped as the amount of changes is too big--> |
| <!--Checking date 2006-8-20 with count of newer 6--><!--Skipped as the amount of changes is too big--> |
| <!--Checking date 2006-3-18 with count of newer 7--><!--Skipped as the amount of changes is too big--> |
| <!--Checking date 2006-3-18 with count of newer 7--><!--Skipped as the amount of changes is too big--> |
| <!--Checking date 2006-3-15 with count of newer 9--><!--Skipped as the amount of changes is too big--> |
| <!--Checking date 2006-2-26 with count of newer 10--><!--Skipped as the amount of changes is too big--> |
| </ul> |
| <h3>Use Cases</h3> |
| <answer id="arch-usecases"> |
| |
| <p> |
| |
| <h5>Just Parse the Command Line</h5> |
| There needs to be a simple API for someone who has an array of strings |
| and wants to parse them. One does not need to search for providers, |
| just ask the infrastructure to do the parse and get the result. |
| <p></p> |
| The correct way to achieve this is to call |
| <code><a href="org/netbeans/api/sendopts/CommandLine.html" shape="rect">CommandLine</a>.getDefault().process(args)</code>. |
| |
| <h5>Parse the Command Line with Own Options</h5> |
| Since version 2.20 one can define own classes with fields and annotate |
| them with <a href="org/netbeans/spi/sendopts/Arg.html" shape="rect">@Arg</a> |
| annotation. Those classes can then be passed into a |
| <a href="org/netbeans/api/sendopts/CommandLine.html#create-java.lang.Class...-" shape="rect"> |
| factory method |
| </a> |
| that creates new <a href="org/netbeans/api/sendopts/CommandLine.html#create-java.lang.Class...-" shape="rect">command line</a>. |
| One can then process the arguments as many times as needed via the |
| <a href="org/netbeans/api/sendopts/CommandLine.html#process-java.lang.String...-" shape="rect">process</a> |
| method. Example: |
| <pre xml:space="preserve"> |
| public final class MyOption implements <a href="http://download.oracle.com/javase/8/docs/api/java/lang/Runnable.html" shape="rect">Runnable</a> { |
| <a href="org/netbeans/spi/sendopts/Arg.html" shape="rect">@Arg</a>(longName="hello") |
| public String name; |
| |
| public void run() { |
| System.out.println("Hello " + name + "!"); |
| } |
| |
| public static void main(String... args) { |
| <a href="org/netbeans/api/sendopts/CommandLine.html" shape="rect">CommandLine</a> line = <a href="org/netbeans/api/sendopts/CommandLine.html#create-java.lang.Class...-" shape="rect">CommandLine.create</a>(MyOption.class); |
| line.<a href="org/netbeans/api/sendopts/CommandLine.html#process-java.lang.String...-" shape="rect">process</a>(args); |
| } |
| } |
| </pre> |
| |
| <p> |
| If the above main class is called with parameters <code>--hello World</code> it |
| will print out <code>Hello World!</code>. |
| </p> |
| |
| |
| <h5>Short and Long options with or without an argument</h5> |
| The standard <code>getopts</code> supports short form of options - e.g. a dash |
| followed with one letter - or long form using two dashes followed with a word. |
| Moreover the long form is optimized for abbrevations. If there are no |
| conflicts between multiple options, then one can only use double dash followed |
| with a prefix of a long option. |
| <p></p> |
| When using the <a href="org/netbeans/spi/sendopts/Arg.html" shape="rect">declarative annotation style</a> |
| one can always specify |
| <code><a href="org/netbeans/spi/sendopts/Arg.html" shape="rect">@Arg</a>(longName="text", shortName='t')</code>. |
| The <code>longName</code> attribute is required, but if there is supposed to be |
| no long version of the argument, it can be set to empty string. |
| <p></p> |
| One can create an <a href="org/netbeans/spi/sendopts/Option.html" shape="rect">Option</a> |
| by calling any of its factory methods |
| (like |
| <a href="org/netbeans/spi/sendopts/Option.html#withoutArgument-char-java.lang.String-" shape="rect">withoutArgument</a>) |
| and provider <code>char</code> for the one letter option and/or string for |
| the long getopts option. |
| |
| <h5>Options with or without an argument</h5> |
| There are three types of options. Those without an argument, those with |
| a required one and those with optional one. Each one can be created |
| by appropriate factory method in the |
| <a href="org/netbeans/spi/sendopts/Option.html" shape="rect">Option</a> class. |
| <p></p> |
| When using the <a href="org/netbeans/spi/sendopts/Arg.html" shape="rect">declarative annotation style</a> |
| one needs to annotate a field of type <code>boolean</code> to create |
| an option without an argument. |
| |
| <h5>Support for --</h5> |
| The getopts compliant command line parsers support <q>--</q>. If |
| these characters do appear on the command line, the rest of it is |
| treated as extra arguments and not processed. The sendopts infrastructure |
| supports this as well. |
| |
| <h5>Multiple Independent CLI Handlers</h5> |
| The handlers for the options need not know about each other and still |
| have to be able to process the command line successfully. Any module |
| which wishes to provide its own options can register its |
| <a href="org/netbeans/spi/sendopts/OptionProcessor.html" shape="rect">OptionProcessor</a> |
| with <a href="../org-openide-util-lookup/org/openide/util/lookup/ServiceProvider.html" shape="rect">@ServiceProvider</a> |
| annotation. Alternatively the module can use the |
| <a href="org/netbeans/spi/sendopts/Arg.html" shape="rect">@Arg</a> annotation |
| of its fields and it will be registered as well. |
| |
| <h5>Extensible Options Set</h5> |
| |
| <p> |
| |
| <b>Q:</b> How shall one write an |
| <a href="org/netbeans/spi/sendopts/OptionProcessor.html" shape="rect">OptionProcessor</a> |
| that recognizes set of basic options, however contains one open <q>slot</q>? |
| The processor wants other modules to provide recognizers for that slot |
| and wants to communicate with them. For example, by default the processor |
| recognizes option <code>--channel <name_of_the_channel></code> |
| which describes a source of data, and stores such data into a <q>sink</q>. |
| There can be multiple sinks - discard the output, save it to file, show |
| it on stdout, stream it to network. The processor itself can handle the |
| copying of data, but does not itself know all the possible <q>sink</q> |
| types. |
| </p> |
| |
| |
| <p> |
| To implement |
| <a href="org/netbeans/spi/sendopts/OptionProcessor.html" shape="rect">OptionProcessor</a> |
| like this one shall define an additional interface to communicate with |
| the <q>sink</q> providers: |
| </p> |
| |
| |
| <pre xml:space="preserve"> |
| package my.module; |
| public interface SinkProvider { |
| /** gets the option (even composite) that this sink needs on command line */ |
| public Option getOption(); |
| |
| /** processes the options and creates a "sink" */ |
| public OutputStream createSink(Env env, Map<Option,String[]> values) throws CommandException; |
| } |
| </pre> |
| |
| <p> |
| Other modules would then registered implementations of this |
| interface in the |
| <code>META-INF/services/my.module.SinkProvider</code> files. |
| The |
| <a href="org/netbeans/spi/sendopts/OptionProcessor.html" shape="rect">OptionProcessor</a> |
| itself would just look all the implementations up, queried for |
| the <q>sinks</q>, and then did the copying: |
| </p> |
| |
| |
| <pre xml:space="preserve"> |
| class CopyingProvider extends OptionProvider { |
| public Option getOption() { |
| List<Option> l = ...; |
| for (SinkProvider sp : Lookup.getDefault().lookupAll(SinkProvider.class)) { |
| l.add(sp.getOption()); |
| } |
| |
| // we need only one provider to be present |
| Option oneOfSinks = OptionGroups.oneOf(l.toArray(new Option[0])); |
| |
| // our channel option |
| Option channel = ...; |
| |
| // the channel option needs to be present as well as a sink |
| return OptionGroups.allOf(channel, oneOfSinks); |
| } |
| |
| public void process(Env env, Map<Option,String[]> values) throws CommandException { |
| OutputStream os = null; |
| for (SinkProvider sp : Lookup.getDefault().lookupAll(SinkProvider.class)) { |
| if (values.containsKey(sp.getOption())) { |
| os = sp.createSink(env, values); |
| break; |
| } |
| } |
| if (os == null) { |
| throw CommandException.exitCode(2); |
| } |
| |
| // process the channel option and |
| // handle the copying to the sink <code>os</code> |
| } |
| } |
| </pre> |
| |
| <p> |
| Another possible approach how to allow sharing of one option between |
| multiple modules is to expose the option definition and its handling |
| code as an interface to other modules, and then let the modules |
| to write their own |
| <a href="org/netbeans/spi/sendopts/OptionProcessor.html" shape="rect">OptionProcessor</a>s. |
| Necessary condition is that each of the processor is uniquely |
| identified by some additional option, so when the shared option appears |
| the infrastructure knows which processor to delegate to. |
| This is demonstrated in the |
| <a href="http://www.netbeans.org/source/browse/contrib/sendopts/test/unit/src/org/netbeans/api/sendopts/Attic/SharedOptionTest.java?rev=1.1.2" shape="rect"> |
| SharedOptionTest</a> which |
| basically does the following: |
| </p> |
| |
| <pre xml:space="preserve"> |
| /** the shared option, part of an interface of some module */ |
| public static final Option SHARED = ...; |
| /** finds value(s) associated with the SHARED option and |
| * creates a JPanel based on them */ |
| public static JPanel getSharedPanel(Map<Option,String[]> args) { ... } |
| </pre> |
| |
| <p> |
| Then each module who wishes to reuse the SHARED option and the |
| factory method that knows how to process their values for their |
| own processing can just: |
| </p> |
| |
| <pre xml:space="preserve"> |
| public static final class ShowDialog extends OptionProcessor { |
| private static final Option DIALOG = Option.withoutArgument('d', "dialog"); |
| |
| protected Set<Option> getOptions() { |
| // the following says that this processor should be invoked |
| // everytime --dialog appears on command line, if the SHARED |
| // option is there, then this processor wants to consume it |
| // as well... |
| return Collections.singleton(Option.allOf(DIALOG, Option.anyOf(SHARED))); |
| } |
| |
| protected void process(Env env, Map<Option, String[]> optionValues) throws CommandException { |
| JPanel p = getSharedPanel(optionvalues); |
| if (p == null) { |
| // show empty dialog |
| } else { |
| // show some dialog containing the panel p |
| } |
| } |
| } |
| </pre> |
| |
| <p> |
| The other modules are then free to write other processors refering to |
| <code>SHARED</code>, for example one can write <code>ShowFrame</code> |
| that does the same, just shows the panel in a frame, etc. The infrastructure |
| guarantees that the exactly one provider which matches the command |
| line options is called. |
| </p> |
| |
| |
| <h5>Printing Full Help Text</h5> |
| Althrough the handlers are provided by independent parties, it must be possible |
| to generate resonable and consistent help description from all of them, |
| so for the end user it appears as well formated and easily understandable. |
| That is why |
| every option can be associated with a short description providing info |
| about what it is useful for using |
| <a href="org/netbeans/spi/sendopts/Option.html#shortDescription-org.netbeans.spi.sendopts.Option-java.lang.String-java.lang.String-" shape="rect"> |
| Option.shortDescription |
| </a> method. When using the |
| <a href="org/netbeans/spi/sendopts/Arg.html" shape="rect">@Arg</a> style, there |
| is an additional <a href="org/netbeans/spi/sendopts/Description.html" shape="rect">@Description</a> |
| annotation which can be used to declaratively associate a localized display name |
| and short description with the option. |
| To get such descriptions for all available options one |
| can use |
| <a href="org/netbeans/api/sendopts/CommandLine.html#usage-java.io.PrintWriter-" shape="rect"> |
| CommandLine.getDefault().usage(java.io.PrintWriter)</a>. |
| |
| <h5>Finding and Reporting when Options Are Not Correct</h5> |
| In case the command line cannot be processed a clean error for programmatic |
| consumation and also one that can be shown to the end user of the command |
| line must be given. This is handled by throwing |
| <a href="org/netbeans/api/sendopts/CommandException.html" shape="rect">CommandException</a> |
| with appropriate message description and exit code. |
| |
| <h5>Processing Extra Command Line Arguments</h5> |
| There can be non-option arguments in the command line and they can freely |
| mix with the option ones. For example the getopts would treat the following |
| command line arguments as the same:<pre xml:space="preserve"> |
| --open X.java Y.java Z.txt |
| X.java Y.java --open Z.txt |
| </pre> if the option <q>open</q> handles <q>extra arguments</q>. |
| The sendopts infrastructure must distinquish between them |
| and pass the non-option ones to the only one handler (active because it |
| processed an option) that knowns how to |
| parse them. It is an error if more than one or no handler expresses |
| an interest in extra arguments and those are given. One can register |
| such option by using the <code> |
| <a href="org/netbeans/spi/sendopts/Option.html#additionalArguments-char-java.lang.String-" shape="rect"> |
| Option.additionalArgument |
| </a> |
| </code> factory method. |
| <p></p> |
| When using the |
| <a href="org/netbeans/spi/sendopts/Arg.html" shape="rect">declarative annotation style</a> |
| one may annotate a field of type <code>String[]</code> which then means |
| this field should be filled with all additional arguments. |
| |
| <h5>Handling Input and Output</h5> |
| Handler's shall not use the input and output streams directly for their execution, they should |
| rely on the framework provided ones. This allows NetBeans based application to |
| transfer the I/O from second started instance to the master one which |
| is already running. From the client side there is the |
| <code><a href="org/netbeans/api/sendopts/CommandLine.html" shape="rect">CommandLine</a>.getDefault().parse</code> |
| methods taking additional arguments like input and output streams. |
| This gets transfered to providers as an |
| <a href="org/netbeans/spi/sendopts/Env.html" shape="rect">Env</a> |
| argument of their methods. |
| |
| <h5>Returning Exit Code</h5> |
| When Handler's get execute (in the order defined by the order of options |
| on the command line), each of them can either execute successfully, or |
| fail. If a handler succeeds, next one is executed, if it fails, the |
| execution is terminated and its return code is returned to the caller. |
| The error can be notified by creating and throwing |
| <a href="org/netbeans/api/sendopts/CommandException.html" shape="rect">CommandException.exitCode(int errorCode)</a>. |
| |
| <h5>Processing Only Extra Command Line Arguments</h5> |
| Sometimes it is desirable to process non-option arguments like file names |
| without providing any option. Handlers can declare interest in such arguments. |
| It is an error if such non-options are provided and no or more than one |
| handler is around to handle them. One can create such option by |
| using <code> |
| <a href="org/netbeans/spi/sendopts/Option.html#defaultArguments--" shape="rect">Option.defaultArguments</a> |
| </code> factory method. With the |
| <a href="org/netbeans/spi/sendopts/Arg.html" shape="rect">declarative annotation style</a> |
| one can annotate a field of type <code>String[]</code> and specify that |
| it is supposed to be <a href="org/netbeans/spi/sendopts/Arg.html#implicit--" shape="rect">implicit</a>. |
| |
| <h5>Only those processor need to process the options are created</h5> |
| For purposes of usage in NetBeans, it is needed to not-initialize those |
| handlers that are not really needed to process certain command line. |
| The infrastructure decides which of them are going to be needed and |
| instantiates only those. This is supported only when using the |
| <a href="org/netbeans/spi/sendopts/Arg.html" shape="rect">declarative annotation style</a> - |
| information about these options is recorded in declarative way and the |
| system can decide without loading the provider classes whether they are |
| present on the command line or not. |
| |
| <h5>Complex Option Relations</h5> |
| Certain CLI processors may need more than one option before they |
| can process the input. For example it is necesary to tune the radio |
| and then also tell what to do with the output. It is unconvenient |
| to process that as one option with argument(s), that is why one can |
| use the |
| <a href="org/netbeans/spi/sendopts/OptionGroups.html#allOf-org.netbeans.spi.sendopts.Option...-" shape="rect"> |
| OptionGroups.allOf</a>, |
| <a href="org/netbeans/spi/sendopts/OptionGroups.html#someOf-org.netbeans.spi.sendopts.Option...-" shape="rect"> |
| OptionGroups.someOf</a>, for example like: <pre xml:space="preserve"> |
| class PP extends OptionProcessor { |
| private static Option tune = Option.requiredArgument(Option.NO_SHORT_NAME, "tune"); |
| private static Option stream = Option.requiredArgument(Option.NO_SHORT_NAME, "stream"); |
| |
| public Set<Option> getOptions() { |
| return Collections.singleton( |
| <a href="org/netbeans/spi/sendopts/OptionGroups.html#allOf-org.netbeans.spi.sendopts.Option...-" shape="rect">OptionGroups.allOf</a>(tune, stream) |
| ); |
| } |
| |
| public void process(Env env, Map>Option,String[]> values) throws CommandException { |
| String freq = values.get(tune)[0]; |
| String output = values.get(stream)[0]; |
| |
| // XXX handle what is needed here |
| } |
| } |
| </pre> |
| When the two options are registered and command line like |
| <q>--tune 91.9 --stream radio1.mp3</q> is being processed, the |
| <code>PP</code>'s <code>process</code> method is going to get |
| called with values <q>91.9</q> and <q>radio1.mp3</q>. |
| <p></p> |
| This kind of grouping is not currently supported with the |
| <a href="org/netbeans/spi/sendopts/Arg.html" shape="rect">declarative annotation style</a> |
| registration. |
| |
| |
| |
| <h5>Alternative Options</h5> |
| Sometimes there may different ways to specify the same option and |
| just one of them or none of them can be provided at given time. |
| For example is there is a way to tune the radio with direct frequency |
| or with name of the station. Just one can be provided and one is needed. |
| This can be specified by using |
| <a href="org/netbeans/spi/sendopts/OptionGroups.html#oneOf-org.netbeans.spi.sendopts.Option...-" shape="rect"> |
| OptionGroups.oneOf</a> factory methods: |
| <pre xml:space="preserve"> |
| Option freq = Option.requiredArgument(Option.NO_SHORT_NAME, "tune"); |
| Option station = Option.requiredArgument(Option.NO_SHORT_NAME, "station"); |
| Option tune = OptionGroups.oneOf(freq, station); |
| </pre> |
| The option <code>tune</code> then signals that just one of the station or |
| freq options can appear and that they both are replaceable. |
| |
| </p> |
| |
| </answer> |
| <h3>Exported Interfaces</h3> |
| |
| This table lists all of the module exported APIs |
| with |
| defined stability classifications. It is generated |
| based on answers to questions about the architecture |
| of the module. <a href="architecture-summary.html">Read them all</a>... |
| |
| |
| <a name="group-java"> |
| <h5>Group of java interfaces</h5> |
| </a> |
| <table cellpadding="1" cellspacing="0" border="0" class="tablebg" width="100%"> |
| <tr> |
| <td> |
| <table border="0" cellpadding="3" cellspacing="1" width="100%"> |
| <tr class="tablersh"> |
| <td align="CENTER" width="25%"><span class="titlectable">Interface Name</span></td><td align="CENTER" width="10%"><span class="titlectable">In/Out</span></td><td align="CENTER" width="10%"><span class="titlectable">Stability</span></td><td align="CENTER"><span class="titlectable">Specified in What Document?</span></td> |
| </tr> |
| <tr class="tabler"> |
| <td>SendOptsAPI</td><td>Exported</td><td><a href="http://wiki.netbeans.org/API_Stability#Official">Official</a></td><td><a name="java-SendOptsAPI"><a href="org/netbeans/api/sendopts/package-summary.html"> |
| .../api/sendopts/package-summary.html</a> |
| <p></p> |
| </a></td> |
| </tr> |
| <tr class="tabler"> |
| <td>SendOptsSPI</td><td>Exported</td><td><a href="http://wiki.netbeans.org/API_Stability#Official">Official</a></td><td><a name="java-SendOptsSPI"><a href="org/netbeans/spi/sendopts/package-summary.html"> |
| .../spi/sendopts/package-summary.html</a> |
| <p></p> |
| </a></td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| </table> |
| <p></p> |
| <a name="group-lookup"> |
| <h5>Group of lookup interfaces</h5> |
| </a> |
| <table cellpadding="1" cellspacing="0" border="0" class="tablebg" width="100%"> |
| <tr> |
| <td> |
| <table border="0" cellpadding="3" cellspacing="1" width="100%"> |
| <tr class="tablersh"> |
| <td align="CENTER" width="25%"><span class="titlectable">Interface Name</span></td><td align="CENTER" width="10%"><span class="titlectable">In/Out</span></td><td align="CENTER" width="10%"><span class="titlectable">Stability</span></td><td align="CENTER"><span class="titlectable">Specified in What Document?</span></td> |
| </tr> |
| <tr class="tabler"> |
| <td>OptionProcessor</td><td>Exported</td><td><a href="http://wiki.netbeans.org/API_Stability#Stable">Stable</a></td><td><a name="lookup-OptionProcessor"><a href="org/netbeans/spi/sendopts/OptionProcessor.html"> |
| .../spi/sendopts/OptionProcessor.html</a> |
| <p></p> |
| <p></p> |
| The sendopts module uses <a href="../org-openide-util-lookup/org/openide/util/Lookup.html" shape="rect">Lookup</a> |
| to get list of all registered <a href="org/netbeans/spi/sendopts/OptionProcessor.html" shape="rect">OptionProcessor</a>s. |
| <p></p> |
| </a></td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| </table> |
| <p></p> |
| <h3>Implementation Details</h3> |
| <h5>Where are the sources for the module?</h5> |
| |
| <p> |
| <p> |
| The sources for the module are in the |
| <a href="http://hg.netbeans.org/" shape="rect">NetBeans Mercurial repositories</a>. |
| </p> |
| </p> |
| |
| <h5>What do other modules need to do to declare a dependency on this one, in addition to or instead of a plain module dependency?</h5> |
| |
| <p> |
| Nothing. |
| </p> |
| |
| <p> |
| Read more about the implementation in the <a href="architecture-summary.html">answers to |
| architecture questions</a>. |
| </p></div> |
| </div> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a name="navbar.bottom"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> |
| <a name="navbar.bottom.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li class="navBarCell1Rev">Overview</li> |
| <li>Package</li> |
| <li>Class</li> |
| <li>Use</li> |
| <li><a href="overview-tree.html">Tree</a></li> |
| <li><a href="deprecated-list.html">Deprecated</a></li> |
| <li><a href="index-files/index-1.html">Index</a></li> |
| <li><a href="help-doc.html">Help</a></li> |
| </ul> |
| <div class="aboutLanguage">org.netbeans.modules.sendopts/2 2.38.1 </div> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li>Prev</li> |
| <li>Next</li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="index.html?overview-summary.html" target="_top">Frames</a></li> |
| <li><a href="overview-summary.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_bottom"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <a name="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| <p class="legalCopy"><small><span class="footnote">Built on September 14 2018. | Copyright © 2017-2018 Apache Software Foundation. All Rights Reserved.</span></small></p> |
| </body> |
| </html> |