Skip to content

Commit 23d13f5

Browse files
committed
CLI-217: More DefaultParser constructor docs.
1 parent 86e6c65 commit 23d13f5

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/main/java/org/apache/commons/cli/DefaultParser.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,44 @@ public class DefaultParser implements CommandLineParser
5757
/** Flag indicating if partial matching of long options is supported. */
5858
private boolean allowPartialMatching;
5959

60-
/** Creates a new DefaultParser instance with partial matching enabled. */
60+
/**
61+
* Creates a new DefaultParser instance with partial matching enabled.
62+
*
63+
* By "partial matching" we mean that given the following code:
64+
* <pre>
65+
* {@code
66+
* final Options options = new Options();
67+
* options.addOption(new Option("d", "debug", false, "Turn on debug."));
68+
* options.addOption(new Option("e", "extract", false, "Turn on extract."));
69+
* options.addOption(new Option("o", "option", true, "Turn on option with argument."));
70+
* }
71+
* </pre>
72+
* with "partial matching" turned on, <code>-de</code> only matches the
73+
* <code>"debug"</code> option. However, with "partial matching" disabled,
74+
* <code>-de</code> would enable both <code>debug</code> as well as
75+
* <code>extract</code> options.
76+
*/
6177
public DefaultParser() {
6278
this.allowPartialMatching = true;
6379
}
6480

6581
/**
6682
* Create a new DefaultParser instance with the specified partial matching policy.
6783
*
84+
* By "partial matching" we mean that given the following code:
85+
* <pre>
86+
* {@code
87+
* final Options options = new Options();
88+
* options.addOption(new Option("d", "debug", false, "Turn on debug."));
89+
* options.addOption(new Option("e", "extract", false, "Turn on extract."));
90+
* options.addOption(new Option("o", "option", true, "Turn on option with argument."));
91+
* }
92+
* </pre>
93+
* with "partial matching" turned on, <code>-de</code> only matches the
94+
* <code>"debug"</code> option. However, with "partial matching" disabled,
95+
* <code>-de</code> would enable both <code>debug</code> as well as
96+
* <code>extract</code> options.
97+
*
6898
* @param allowPartialMatching if partial matching of long options shall be enabled
6999
*/
70100
public DefaultParser(final boolean allowPartialMatching) {

src/site/xdoc/usage.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ CommandLine cmd = parser.parse( options, args);</source>
9090
else {
9191
// print the date
9292
}</source>
93+
<p>
94+
<h4>Note.</h4>
95+
As of version 1.5-SNAPSHOT (as of 7/31/2017), the
96+
<code>DefaultParser</code>'s constructor now has an override with
97+
the signature <code>DefaultParser(final boolean allowPartialMatching)</code>.
98+
Given the following code:
99+
<source>final Options options = new Options();
100+
options.addOption(new Option("d", "debug", false, "Turn on debug."));
101+
options.addOption(new Option("e", "extract", false, "Turn on extract."));
102+
options.addOption(new Option("o", "option", true, "Turn on option with argument."));</source>
103+
we define "partial matching" as <code>-de</code> only matching the
104+
<code>"debug"</code> option. We can consequently, now, turn this off and have
105+
<code>-de</code> match both the <code>debug</code> option as well as the
106+
<code>extract</code> option.
107+
</p>
93108
</subsection>
94109
<subsection name="International Time">
95110
<p>

0 commit comments

Comments
 (0)