Skip to content

Commit 5c427dd

Browse files
author
John Keyes
committed
added Pete Maddocks patch for having options created only with a longOpt returned from getOptions
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@129811 13f79535-47bb-0310-9956-ffa450edef68
1 parent f1a32a5 commit 5c427dd

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import java.util.Iterator;
6969
import java.util.List;
7070
import java.util.Map;
71+
import java.util.*;
7172

7273
/** <p>Main entry-point into the library.</p>
7374
*
@@ -178,7 +179,20 @@ public Options addOption(Option opt) {
178179
* @return read-only Collection of {@link Option} objects in this descriptor
179180
*/
180181
public Collection getOptions() {
181-
return Collections.unmodifiableCollection( shortOpts.values() );
182+
List opts = new ArrayList( shortOpts.values() );
183+
184+
// now look through the long opts to see if there are any Long-opt
185+
// only options
186+
Iterator iter = longOpts.values().iterator();
187+
while (iter.hasNext())
188+
{
189+
Object item = iter.next();
190+
if (!opts.contains(item))
191+
{
192+
opts.add(item);
193+
}
194+
}
195+
return Collections.unmodifiableCollection( opts );
182196
}
183197

184198
/** <p>Returns the required options as a

0 commit comments

Comments
 (0)