jkeyes 2002/11/27 15:22:02 Modified: cli/src/java/org/apache/commons/cli Parser.java Log: added support for *boolean/flag* options from properties Revision Changes Path 1.10 +25 -6 jakarta-commons/cli/src/java/org/apache/commons/cli/Parser.java Index: Parser.java =================================================================== RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/Parser.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- Parser.java 25 Nov 2002 23:43:40 -0000 1.9 +++ Parser.java 27 Nov 2002 23:22:02 -0000 1.10 @@ -255,9 +255,28 @@ String option = e.nextElement().toString(); if( !cmd.hasOption( option ) ) { Option opt = options.getOption( option ); - if( opt.getValues() == null || opt.getValues().length == 0 ) { - opt.addValue( properties.getProperty( option ) ); + + // get the value from the properties instance + String value = properties.getProperty( option ); + + if( opt.hasArgs() ) { + if( opt.getValues() == null || opt.getValues().length == 0 ) { + try { + opt.addValue( value ); + } + catch( RuntimeException exp ) { + // if we cannot add the value don't worry about it + } + } } + else if ( ! ( "yes".equalsIgnoreCase( value ) || + "true".equalsIgnoreCase( value ) || + "1".equalsIgnoreCase( value) ) ) { + // if the value is not yes, true or 1 then don't add the + // option to the CommandLine + break; + } + cmd.addOption( opt ); } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>