forked from jontejj/jargo
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
I think the API would be much cleaner if ParsedArguments#get(Argument<T>) returned Optional<T> for parameters that had not been specified in the args or do not have a defaultValue.
This would also avoid the need to use ParsedArguments#wasGiven(Argument<T>).
For example:
import com.google.common.base.Optional;
import org.junit.Test;
import static org.fest.assertions.Assertions.assertThat;
import static se.softhouse.jargo.Arguments.stringArgument;
public class OptionalTest {
@Test
public void optional() {
final Argument<Optional<String>> arg1 = stringArgument("s1")
.description("string1")
.build();
final Argument<String> arg2 = stringArgument("s2")
.description("string2")
.defaultValue("hello")
.build();
final Argument<Optional<String>> arg3 = stringArgument("s3")
.description("string3")
.build();
final ParsedArguments args = CommandLineParser
.withArguments(arg1, arg2, arg3)
.parse("--s3 this");
assertThat(args.get(arg1)).isEqualTo(Optional.absent());
assertThat(args.get(arg2)).isEqualTo("hello");
assertThat(args.get(arg3)).isEqualTo(Optional.of("this"));
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels