Skip to content

Commit be7dfa5

Browse files
author
John Keyes
committed
added support for *boolean/flag* options from properties
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@129854 13f79535-47bb-0310-9956-ffa450edef68
1 parent 7e6dedb commit be7dfa5

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//cli/src/java/org/apache/commons/cli/Parser.java,v 1.9 2002/11/25 23:43:40 jkeyes Exp $
3-
* $Revision: 1.9 $
4-
* $Date: 2002/11/25 23:43:40 $
2+
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//cli/src/java/org/apache/commons/cli/Parser.java,v 1.10 2002/11/27 23:22:02 jkeyes Exp $
3+
* $Revision: 1.10 $
4+
* $Date: 2002/11/27 23:22:02 $
55
*
66
* ====================================================================
77
*
@@ -74,7 +74,7 @@
7474
*
7575
* @author John Keyes (john at integralsource.com)
7676
* @see Parser
77-
* @version $Revision: 1.9 $
77+
* @version $Revision: 1.10 $
7878
*/
7979
public abstract class Parser implements CommandLineParser {
8080

@@ -255,9 +255,28 @@ private void processProperties( Properties properties ) {
255255
String option = e.nextElement().toString();
256256
if( !cmd.hasOption( option ) ) {
257257
Option opt = options.getOption( option );
258-
if( opt.getValues() == null || opt.getValues().length == 0 ) {
259-
opt.addValue( properties.getProperty( option ) );
258+
259+
// get the value from the properties instance
260+
String value = properties.getProperty( option );
261+
262+
if( opt.hasArgs() ) {
263+
if( opt.getValues() == null || opt.getValues().length == 0 ) {
264+
try {
265+
opt.addValue( value );
266+
}
267+
catch( RuntimeException exp ) {
268+
// if we cannot add the value don't worry about it
269+
}
270+
}
260271
}
272+
else if ( ! ( "yes".equalsIgnoreCase( value ) ||
273+
"true".equalsIgnoreCase( value ) ||
274+
"1".equalsIgnoreCase( value) ) ) {
275+
// if the value is not yes, true or 1 then don't add the
276+
// option to the CommandLine
277+
break;
278+
}
279+
261280
cmd.addOption( opt );
262281
}
263282
}

0 commit comments

Comments
 (0)