Softhouse / jargo

Argument and options parser for java
Other
17 stars 0 forks source link

optionArgument with defaultValue(true) cannot be set to false #29

Closed tomasbjerre closed 8 years ago

tomasbjerre commented 8 years ago

When I do:

Argument<Boolean> enableLogging = optionArgument("-l", "--enable-logging")
                                    .defaultValue(true).build();
ParsedArguments arg = CommandLineParser.withArguments(enableLogging);
arg.get(enableLogging) //Always true!

"enableLogging" cannot be set to false? If I dont supply the argument it will default to true, if I supply it it will be set to true. I must use defaultValue null or false, otherwise there is no way of setting it to false?

Perhaps optionArgument should not have a default value?

jontejj commented 8 years ago

In https://github.com/Softhouse/jargo/blob/06b7b4abe0b94c286ac00cd989d36dd141dee8ed/jargo/src/test/java/se/softhouse/jargo/stringparsers/OptionalArgumentTest.java there is a test:

@Test
public void testThatOptionalIsFalseWhenArgumentIsGivenAndDefaultIsTrue() throws ArgumentException
{
    assertThat(optionArgument("--disable-logging").defaultValue(true).parse("--disable-logging")).isFalse();
}

Perhaps you're passing in the wrong string arguments?

tomasbjerre commented 8 years ago

Ok, I'll just use wasGiven, it returns what I would expect get to return.