Softhouse / jargo

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

No way to tell if user omitted an optional number type. #31

Closed Fyorl closed 8 years ago

Fyorl commented 8 years ago

If you create a NumberType argument such as bigDecimalArgument or integerArgument and you do not specify it as required() then there is no way, within your program, to tell if the user has invoked your program with the argument or not. Since all NumberType arguments inherit a defaultValue() of 0, your program cannot tell if the user has specified 0 at the command line or if the user did not specify a number at all.

This behaviour does not strike me as particularly intuitive as there can be a very large semantic difference between a user specifying a value and a user omitting a value entirely.

Since ParsedArguments.get() is marked as @Nullable, I propose that this return null for an argument that is not required(), has no explicit defaultValue() and has not been provided a value on the command line. Ideally ParsedArguments.get() should return an Optional though.

jontejj commented 8 years ago

You can use ParsedArguments#wasGiven to detect this. The reason ParsedArguments.get() is @Nullable is that sometimes null is used as the default. Having both default values and Optional is confusing IMO so that's why I made it nullable instead of Optional. My thought was that either you make it required or you have a default value.

Fyorl commented 8 years ago

That's my fault for not reading the documentation thoroughly, thank you for the response.

jontejj commented 8 years ago

I would appreciate it if you closed this issue:)

Fyorl commented 8 years ago

Sorry, thought I already had.