blob: 0adf10ce7ec5cdb64db055e17dee814dbd7e71f6 [file] [log] [blame]
<!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 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>org.apache.commons.cli.avalon (Apache JMeter dist API)</title>
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.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="org.apache.commons.cli.avalon (Apache JMeter dist 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><a href="../../../../../overview-summary.html">Overview</a></li>
<li class="navBarCell1Rev">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">Help</a></li>
</ul>
<div class="aboutLanguage"><b>Apache JMeter</b></div>
</div>
<div class="subNav">
<ul class="navList">
<li>Prev&nbsp;Package</li>
<li><a href="../../../../../org/apache/jmeter/package-summary.html">Next&nbsp;Package</a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/commons/cli/avalon/package-summary.html" target="_top">Frames</a></li>
<li><a href="package-summary.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;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 title="Package" class="title">Package&nbsp;org.apache.commons.cli.avalon</h1>
<div class="docSummary">
<div class="block">Utility code for parsing command-line options.</div>
</div>
<p>See:&nbsp;<a href="#package.description">Description</a></p>
</div>
<div class="contentContainer">
<ul class="blockList">
<li class="blockList">
<table class="typeSummary" border="0" cellpadding="3" cellspacing="0" summary="Interface Summary table, listing interfaces, and an explanation">
<caption><span>Interface Summary</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Interface</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tbody>
<tr class="altColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/cli/avalon/ParserControl.html" title="interface in org.apache.commons.cli.avalon">ParserControl</a></td>
<td class="colLast">
<div class="block">ParserControl is used to control particular behaviour of the parser.</div>
</td>
</tr>
</tbody>
</table>
</li>
<li class="blockList">
<table class="typeSummary" border="0" cellpadding="3" cellspacing="0" summary="Class Summary table, listing classes, and an explanation">
<caption><span>Class Summary</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Class</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tbody>
<tr class="altColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/cli/avalon/AbstractParserControl.html" title="class in org.apache.commons.cli.avalon">AbstractParserControl</a></td>
<td class="colLast">
<div class="block">Class to inherit from so when in future when new controls are added clients
will no have to implement them.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/cli/avalon/CLArgsParser.html" title="class in org.apache.commons.cli.avalon">CLArgsParser</a></td>
<td class="colLast">
<div class="block">Parser for command line arguments.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/cli/avalon/CLOption.html" title="class in org.apache.commons.cli.avalon">CLOption</a></td>
<td class="colLast">
<div class="block">Basic class describing an instance of option.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/cli/avalon/CLOptionDescriptor.html" title="class in org.apache.commons.cli.avalon">CLOptionDescriptor</a></td>
<td class="colLast">
<div class="block">Basic class describing an type of option.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/cli/avalon/CLUtil.html" title="class in org.apache.commons.cli.avalon">CLUtil</a></td>
<td class="colLast">
<div class="block">CLUtil offers basic utility operations for use both internal and external to
package.</div>
</td>
</tr>
</tbody>
</table>
</li>
</ul>
<a name="package.description">
<!-- -->
</a>
<h2 title="Package org.apache.commons.cli.avalon Description">Package org.apache.commons.cli.avalon Description</h2>
<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 &lt; 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>
</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><a href="../../../../../overview-summary.html">Overview</a></li>
<li class="navBarCell1Rev">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">Help</a></li>
</ul>
<div class="aboutLanguage"><b>Apache JMeter</b></div>
</div>
<div class="subNav">
<ul class="navList">
<li>Prev&nbsp;Package</li>
<li><a href="../../../../../org/apache/jmeter/package-summary.html">Next&nbsp;Package</a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/commons/cli/avalon/package-summary.html" target="_top">Frames</a></li>
<li><a href="package-summary.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;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>Copyright © 1998-2022 Apache Software Foundation. All Rights Reserved.</small></p>
</body>
</html>