Skip to content

Commit b2fa954

Browse files
committed
[CLI-214] Added method Options.addOption(String, String), thanks to Alexandru Mocanu for the patch.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@1442985 13f79535-47bb-0310-9956-ffa450edef68
1 parent f489ea1 commit b2fa954

4 files changed

Lines changed: 22 additions & 2 deletions

File tree

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@
127127
<role>unit tests</role>
128128
</roles>
129129
</contributor>
130+
<contributor>
131+
<name>Alexandru Mocanu</name>
132+
</contributor>
130133

131134
</contributors>
132135

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<body>
2424

2525
<release version="1.3" date="in SVN">
26+
<action type="add" dev="tn" issue="CLI-214" due-to="Alexandru Mocanu">
27+
Added new method Options.addOption(String, String).
28+
</action>
2629
<action type="fix" dev="tn" issue="CLI-227" due-to="Duncan Jones">
2730
Changed unit tests to junit 4 annotation style.
2831
</action>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public class Option implements Cloneable, Serializable
7979

8080
/**
8181
* Creates an Option using the specified parameters.
82+
* The option does not take an argument.
8283
*
8384
* @param opt short representation of the option
8485
* @param description describes the function of the option

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ Collection<OptionGroup> getOptionGroups()
9999
return new HashSet<OptionGroup>(optionGroups.values());
100100
}
101101

102+
/**
103+
* Add an option that only contains a short name.
104+
* The option does not take an argument.
105+
*
106+
* @param opt Short single-character name of the option.
107+
* @param description Self-documenting description
108+
* @return the resulting Options instance
109+
* @since 1.3
110+
*/
111+
public Options addOption(String opt, String description)
112+
{
113+
addOption(opt, null, false, description);
114+
return this;
115+
}
116+
102117
/**
103118
* Add an option that only contains a short-name.
104119
* It may be specified as requiring an argument.
@@ -111,7 +126,6 @@ Collection<OptionGroup> getOptionGroups()
111126
public Options addOption(String opt, boolean hasArg, String description)
112127
{
113128
addOption(opt, null, hasArg, description);
114-
115129
return this;
116130
}
117131

@@ -128,7 +142,6 @@ public Options addOption(String opt, boolean hasArg, String description)
128142
public Options addOption(String opt, String longOpt, boolean hasArg, String description)
129143
{
130144
addOption(new Option(opt, longOpt, hasArg, description));
131-
132145
return this;
133146
}
134147

0 commit comments

Comments
 (0)