| <!DOCTYPE HTML> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (17) --> |
| <title>org.apache.commons.cli.avalon (Apache JMeter dist API)</title> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <meta name="description" content="declaration: package: org.apache.commons.cli.avalon"> |
| <meta name="generator" content="javadoc/PackageWriterImpl"> |
| <link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style"> |
| <link rel="stylesheet" type="text/css" href="../../../../../script-dir/jquery-ui.min.css" title="Style"> |
| <link rel="stylesheet" type="text/css" href="../../../../../jquery-ui.overrides.css" title="Style"> |
| <script type="text/javascript" src="../../../../../script.js"></script> |
| <script type="text/javascript" src="../../../../../script-dir/jquery-3.6.1.min.js"></script> |
| <script type="text/javascript" src="../../../../../script-dir/jquery-ui.min.js"></script> |
| </head> |
| <body class="package-declaration-page"> |
| <script type="text/javascript">var evenRowColor = "even-row-color"; |
| var oddRowColor = "odd-row-color"; |
| var tableTab = "table-tab"; |
| var activeTableTab = "active-table-tab"; |
| var pathtoroot = "../../../../../"; |
| loadScripts(document, 'script');</script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <div class="flex-box"> |
| <header role="banner" class="flex-header"> |
| <nav role="navigation"> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="top-nav" id="navbar-top"> |
| <div class="skip-nav"><a href="#skip-navbar-top" title="Skip navigation links">Skip navigation links</a></div> |
| <div class="about-language"><b>Apache JMeter</b></div> |
| <ul id="navbar-top-firstrow" class="nav-list" title="Navigation"> |
| <li><a href="../../../../../index.html">Overview</a></li> |
| <li class="nav-bar-cell1-rev">Package</li> |
| <li>Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../../../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../../../../index-all.html">Index</a></li> |
| <li><a href="../../../../../help-doc.html#package">Help</a></li> |
| </ul> |
| </div> |
| <div class="sub-nav"> |
| <div> |
| <ul class="sub-nav-list"> |
| <li>Package: </li> |
| <li><a href="#package-description">Description</a> | </li> |
| <li>Related Packages | </li> |
| <li><a href="#class-summary">Classes and Interfaces</a></li> |
| </ul> |
| </div> |
| <div class="nav-list-search"><label for="search-input">SEARCH:</label> |
| <input type="text" id="search-input" value="search" disabled="disabled"> |
| <input type="reset" id="reset-button" value="reset" disabled="disabled"> |
| </div> |
| </div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| <span class="skip-nav" id="skip-navbar-top"></span></nav> |
| </header> |
| <div class="flex-content"> |
| <main role="main"> |
| <div class="header"> |
| <h1 title="Package org.apache.commons.cli.avalon" class="title">Package org.apache.commons.cli.avalon</h1> |
| </div> |
| <hr> |
| <div class="package-signature">package <span class="element-name">org.apache.commons.cli.avalon</span></div> |
| <section class="package-description" id="package-description"> |
| <div class="block">Utility code for parsing command-line options. |
| <br> |
| <p style="font-weight:bold"> |
| These classes were originally in the Avalon project in the package org.apache.avalon.excalibur.cli |
| </p> |
| |
| <h2>Introduction</h2> |
| <p>The utilities in <code>org.apache.commons.cli.avalon</code> assist |
| you in parsing command line options during startup time. It allows you |
| to associate a short option and a long option to the same command, and |
| then test for it in a switch statement.</p> |
| <a id="doc.Usage"></a> |
| <h2>Usage Example</h2> |
| <pre> |
| import java.util.List; |
| |
| import org.apache.commons.cli.avalon.CLArgsParser; |
| import org.apache.commons.cli.avalon.CLOption; |
| import org.apache.commons.cli.avalon.CLOptionDescriptor; |
| import org.apache.commons.cli.avalon.CLUtil; |
| |
| /** |
| * Demonstrates the excalibur command-line parsing utility. |
| * |
| */ |
| public class CLDemo { |
| // Define our short one-letter option identifiers. |
| protected static final int HELP_OPT = 'h'; |
| protected static final int VERSION_OPT = 'v'; |
| protected static final int MSG_OPT = 'm'; |
| |
| /** |
| * Define the understood options. Each CLOptionDescriptor contains: |
| * - The "long" version of the option. Eg, "help" means that "--help" will |
| * be recognised. |
| * - The option flags, governing the option's argument(s). |
| * - The "short" version of the option. Eg, 'h' means that "-h" will be |
| * recognised. |
| * - A description of the option. |
| */ |
| protected static final CLOptionDescriptor [] options = new CLOptionDescriptor [] { |
| new CLOptionDescriptor("help", |
| CLOptionDescriptor.ARGUMENT_DISALLOWED, |
| HELP_OPT, |
| "print this message and exit"), |
| new CLOptionDescriptor("version", |
| CLOptionDescriptor.ARGUMENT_DISALLOWED, |
| VERSION_OPT, |
| "print the version information and exit"), |
| new CLOptionDescriptor("msg", |
| CLOptionDescriptor.ARGUMENT_REQUIRED, |
| MSG_OPT, |
| "the message to print"), |
| }; |
| |
| public static void main(String args[]) { |
| // Parse the arguments |
| CLArgsParser parser = new CLArgsParser(args, options); |
| |
| if( null != parser.getErrorString() ) { |
| System.err.println( "Error: " + parser.getErrorString() ); |
| return; |
| } |
| |
| // Get a list of parsed options |
| List clOptions = parser.getArguments(); |
| int size = clOptions.size(); |
| |
| for (int i = 0; i < size; i++) { |
| CLOption option = (CLOption) clOptions.get(i); |
| |
| switch (option.getId()) { |
| case CLOption.TEXT_ARGUMENT: |
| System.out.println("Unknown arg: "+option.getArgument()); |
| break; |
| |
| case HELP_OPT: |
| printUsage(); |
| break; |
| |
| case VERSION_OPT: |
| printVersion(); |
| break; |
| |
| |
| case MSG_OPT: |
| System.out.println(option.getArgument()); |
| break; |
| } |
| } |
| } |
| |
| private static void printVersion() { |
| System.out.println("1.0"); |
| System.exit(0); |
| } |
| |
| private static void printUsage() { |
| String lSep = System.getProperty("line.separator"); |
| StringBuffer msg = new StringBuffer(); |
| msg.append("------------------------------------------------------------------------ ").append(lSep); |
| msg.append("Excalibur command-line arg parser demo").append(lSep); |
| msg.append("Usage: java "+CLDemo.class.getName()+" [options]").append(lSep).append(lSep); |
| msg.append("Options: ").append(lSep); |
| msg.append(CLUtil.describeOptions(CLDemo.options).toString()); |
| System.out.println(msg.toString()); |
| System.exit(0); |
| } |
| } |
| </pre> |
| |
| <h2>Parsing Rules</h2> |
| <p> |
| The command line is parsed according to the following rules. There are |
| two forms of options in this package, the Long form and the Short form. |
| The long form of an option is preceded by the '--' characters while the |
| short form is preceded by a single '-'. Some example options would be; |
| "--an-option", "-a", "--day", "-s -f -a". |
| </p> |
| <p> |
| In the tradition of UNIX programs, the short form of an option can occur |
| immediately after another short form option. So if 'a', 'b' and 'c' are |
| short forms of options that take no parameters then the following |
| command lines are equivalent: "-abc", "-a -bc", "-a -b -c", "-ab -c", etc. |
| </p> |
| <p> |
| Options can also accept arguments if specified. You can specify that an |
| option requires an argument in which the text immediately following the |
| option will be considered to be an argument to the option. So if 'a' was an |
| option that required an argument then the following would be equivalent; |
| "-abc", "-a bc" (namely the option 'a' with argument 'bc'). |
| </p> |
| <p> |
| Options can also specify optional arguments. In this case if there is any |
| text immediately following the option character then it is considered an |
| argument. Otherwise, the option has no arguments. For example if 'a' was an |
| option that required an optional argument then "-abc" is an option 'a' with |
| argument "bc" while "-a bc" is an option 'a' with no argument, followed by |
| the text "bc". </p> |
| <p>It is also possible to place an '=' sign between the option |
| and its argument. So if we assume that a is an option that |
| requires an argument then the following are equivalent; |
| "-a=bc" and "-abc". |
| </p> |
| <p> |
| In the case of a long option with an optional argument, the '=' sign is required. |
| For example. --optarg=1, not --optarg 1. |
| </p> |
| <p> |
| In some cases it is also necessary to disable command line parsing so that you |
| can pass a text argument to the program that starts with a '-' character. To do |
| this insert the sequence '--' onto the command line with no text immediately |
| following it. This will disable processing for the rest of the command line. |
| The '--' characters will not be passed to the user program. For instance the |
| line "-- -b" would result in the program being passed the |
| text "-b" (ie. not as an option). |
| </p></div> |
| </section> |
| <section class="summary"> |
| <ul class="summary-list"> |
| <li> |
| <div id="class-summary"> |
| <div class="table-tabs" role="tablist" aria-orientation="horizontal"><button id="class-summary-tab0" role="tab" aria-selected="true" aria-controls="class-summary.tabpanel" tabindex="0" onkeydown="switchTab(event)" onclick="show('class-summary', 'class-summary', 2)" class="active-table-tab">All Classes and Interfaces</button><button id="class-summary-tab1" role="tab" aria-selected="false" aria-controls="class-summary.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('class-summary', 'class-summary-tab1', 2)" class="table-tab">Interfaces</button><button id="class-summary-tab2" role="tab" aria-selected="false" aria-controls="class-summary.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('class-summary', 'class-summary-tab2', 2)" class="table-tab">Classes</button></div> |
| <div id="class-summary.tabpanel" role="tabpanel"> |
| <div class="summary-table two-column-summary" aria-labelledby="class-summary-tab0"> |
| <div class="table-header col-first">Class</div> |
| <div class="table-header col-last">Description</div> |
| <div class="col-first even-row-color class-summary class-summary-tab2"><a href="AbstractParserControl.html" title="class in org.apache.commons.cli.avalon">AbstractParserControl</a></div> |
| <div class="col-last even-row-color class-summary class-summary-tab2"> |
| <div class="block">Class to inherit from so when in future when new controls are added clients |
| will no have to implement them.</div> |
| </div> |
| <div class="col-first odd-row-color class-summary class-summary-tab2"><a href="CLArgsParser.html" title="class in org.apache.commons.cli.avalon">CLArgsParser</a></div> |
| <div class="col-last odd-row-color class-summary class-summary-tab2"> |
| <div class="block">Parser for command line arguments.</div> |
| </div> |
| <div class="col-first even-row-color class-summary class-summary-tab2"><a href="CLOption.html" title="class in org.apache.commons.cli.avalon">CLOption</a></div> |
| <div class="col-last even-row-color class-summary class-summary-tab2"> |
| <div class="block">Basic class describing an instance of option.</div> |
| </div> |
| <div class="col-first odd-row-color class-summary class-summary-tab2"><a href="CLOptionDescriptor.html" title="class in org.apache.commons.cli.avalon">CLOptionDescriptor</a></div> |
| <div class="col-last odd-row-color class-summary class-summary-tab2"> |
| <div class="block">Basic class describing an type of option.</div> |
| </div> |
| <div class="col-first even-row-color class-summary class-summary-tab2"><a href="CLUtil.html" title="class in org.apache.commons.cli.avalon">CLUtil</a></div> |
| <div class="col-last even-row-color class-summary class-summary-tab2"> |
| <div class="block">CLUtil offers basic utility operations for use both internal and external to |
| package.</div> |
| </div> |
| <div class="col-first odd-row-color class-summary class-summary-tab1"><a href="ParserControl.html" title="interface in org.apache.commons.cli.avalon">ParserControl</a></div> |
| <div class="col-last odd-row-color class-summary class-summary-tab1"> |
| <div class="block">ParserControl is used to control particular behaviour of the parser.</div> |
| </div> |
| </div> |
| </div> |
| </div> |
| </li> |
| </ul> |
| </section> |
| </main> |
| <footer role="contentinfo"> |
| <hr> |
| <p class="legal-copy"><small>Copyright © 1998-2024 Apache Software Foundation. All Rights Reserved.</small></p> |
| </footer> |
| </div> |
| </div> |
| </body> |
| </html> |