-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathparser.xml
More file actions
58 lines (53 loc) · 2 KB
/
Copy pathparser.xml
File metadata and controls
58 lines (53 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?xml version="1.0"?>
<document>
<properties>
<author email="jbjk@mac.com">John Keyes</author>
<title>Creating a command line parser</title>
</properties>
<body>
<section name="Creating a Parser">
<p>
The
<a href="apidocs/org/apache/commons/cli/CommandLineParserFactory.html#newParser()">newParser</a>
method on <a href="apidocs/org/apache/commons/cli/CommandLineParserFactory.html">
CommandLineParserFactory</a> is used to create command line
parser instances.
</p>
<source>
// create a command line parser
CommandLineParser parser = CommandLineParserFactory.newParser();</source>
</section>
<section name="The right tool for the job">
<p>
Different applications may require different parsing implementation
strategies. CLI ships with two implementations: <a href="apidocs/org/apache/commons/cli/PosixParser.html">
PosixParser</a> and <a href="apidocs/org/apache/commons/cli/GnuParser.html">
GnuParser</a>. Both of these implement the <a href="apidocs/org/apache/commons/cli/CommandLineParser.html">
CommandLineParser</a> interface.
</p>
<source>
// parser is a PosixParser
CommandLineParser parser = CommandLineParserFactory.newParser();
// parser is a GnuParser
parser = CommandLineParserFactory.newParser( "org.apache.commons.cli.GnuParser" );
</source>
</section>
<section name="Parse the command line">
<p>
Now that a parser has been created the command line tokens can be
parsed. The two <code>parse</code> methods on
<a href="apidocs/org/apache/commons/cli/CommandLineParser.html">CommandLineParser</a>
perform this task.
</p>
<source>
public static void main( String[] args ) {
// create the options
Options options = ...;
// create the parser
CommandLine parser = ...;
// parse the command line tokens
CommandLine cmd = parser.parse( options, args );
}</source>
</section>
</body>
</document>