diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentDefinitions.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentDefinitions.java index 69181df8c..1d4d497e1 100755 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentDefinitions.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentDefinitions.java @@ -216,6 +216,14 @@ class ArgumentDefinition { Class argumentType = sourceField.getType(); return Collection.class.isAssignableFrom(argumentType) || sourceField.getType().isArray(); } + + /** + * Is this argument a flag (meaning a boolean value whose presence indicates 'true'). + * @return True if this argument is a flag. + */ + public boolean isFlag() { + return (sourceField.getType() == Boolean.class) || (sourceField.getType() == Boolean.TYPE); + } } /** diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentMatches.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentMatches.java index 6058c03f1..d45d1e64d 100755 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentMatches.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentMatches.java @@ -177,12 +177,13 @@ class ArgumentMatch { /** * Does this argument already have a value at the given site? - * Arguments are only allowed to be single-valued. + * Arguments are only allowed to be single-valued per site, and + * flags aren't allowed a value at all. * @param index Index at which to check for values. * @return True if the argument has a value at the given site. False otherwise. */ public boolean hasValueAtSite( int index ) { - return indices.get(index) != null && indices.get(index).size() >= 1; + return (indices.get(index) != null && indices.get(index).size() >= 1) || isArgumentFlag(); } /** @@ -197,4 +198,12 @@ class ArgumentMatch { } return values; } + + /** + * Convenience method returning true if the definition is a flag. + * @return True if definition is known to be a flag; false if not known to be a flag. + */ + private boolean isArgumentFlag() { + return definition != null && definition.isFlag(); + } } \ No newline at end of file diff --git a/java/test/org/broadinstitute/sting/utils/cmdLine/ParsingEngineTest.java b/java/test/org/broadinstitute/sting/utils/cmdLine/ParsingEngineTest.java index b8d03fe53..96a062a8d 100755 --- a/java/test/org/broadinstitute/sting/utils/cmdLine/ParsingEngineTest.java +++ b/java/test/org/broadinstitute/sting/utils/cmdLine/ParsingEngineTest.java @@ -345,4 +345,18 @@ public class ParsingEngineTest extends BaseTest { @Argument(doc="my arg") Integer myArg; } + + @Test(expected=InvalidArgumentValueException.class) + public void booleanWithParameterTest() { + final String[] commandLine = new String[] {"--mybool", "true"}; + + parsingEngine.addArgumentSources( BooleanArgProvider.class ); + ArgumentMatches argumentMatches = parsingEngine.parse( commandLine ); + parsingEngine.validate(argumentMatches); + } + + private class BooleanArgProvider { + @Argument(doc="my bool") + boolean myBool; + } }