8000 When extracting option values from properties, options with a single … · apache/commons-cli@1314233 · GitHub
Skip to content

Commit 1314233

Browse files
author
Robert James Oxspring
committed
When extracting option values from properties, options with a single argument can now be processed successfully.
BR: 31148 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@130112 13f79535-47bb-0310-9956-ffa450edef68
1 parent 798f9e5 commit 1314233

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @author John Keyes (john at integralsource.com)
2929
* @see Parser
30-
* @version $Revision: 1.17 $
30+
* @version $Revision: 1.18 $
3131
*/
3232
public abstract class Parser implements CommandLineParser {
3333

@@ -243,7 +243,7 @@ private void processProperties(Properties properties)
243243
// get the value from the properties instance
244244
String value = properties.getProperty(option);
245245

246-
if (opt.hasArgs())
246+
if (opt.hasArg())
247247
{
248248
if ((opt.getValues() == null)
249249
|| (opt.getValues().length == 0))

src/test/org/apache/commons/cli/BugsTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.PrintStream;
2020
import java.io.PrintWriter;
2121
import java.io.StringWriter;
22+
import java.util.Properties;
2223

2324
import junit.framework.Test;
2425
import junit.framework.TestCase;
@@ -479,5 +480,22 @@ public void test27635() {
479480
"footer"+EOL
480481
,out.toString());
481482
}
483+
484+
public void test31148() throws ParseException {
485+
Option multiArgOption = new Option("o","option with multiple args");
486+
multiArgOption.setArgs(1);
487+
488+
Options options = new Options();
489+
options.addOption(multiArgOption);
490+
491+
Parser parser = new PosixParser();
492+
String[] args = new String[]{};
493+
Properties props = new Properties();
494+
props.setProperty("o","ovalue");
495+
CommandLine cl = parser.parse(options,args,props);
496+
497+
assertTrue(cl.hasOption('o'));
498+
assertEquals("ovalue",cl.getOptionValue('o'));
499+
}
482500

483501
}

0 commit comments

Comments
 (0)