-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unparsing skips arguments with values equal to the argument type's default value #850
Comments
The code causing this behaviour is in
Changing the function body to the code below makes unparsing behave as I described in the original post.
This line forces Required arguments to always be output:
Commenting out this line allows value arguments to be output when Default != default(T) and value == default(T):
|
I was also very surprised to see arguments being skipped for options that are required with SkipDefault set to true. The generated command line string cannot be successfully parsed always as required options may not be present. I require a workaround now. The value of enum type I'm using will start explicitly from 1 so that the default value of 0 will not be used and the enum will be unparsed always. |
I raised a PR #852 which fixes this bug. |
Any news on that? I'm having a similar problem. |
Using CommandLineParser 2.9.1, the unparsing behaviour with
SkipDefault = true
seems to be incorrect. Here is a test app to reproduce the behaviour.There are 2 compulsory arguments, one with a
Default
value and one without aDefault
value.CompulsoryWithDefault
andOptional
have theirDefault
values set to any value that is notdefault(int)
.The test app's console output shows the unparsed command line for the 3 sets of arguments
The unparsed command line for the first case will fail round trip parsing because the compulsory
-c
and-d
arguments are missing and-o
is missing soOptional
will have a value of 1 instead of 0. The unparsed command line for the second case will also fail round trip parsing because the compulsory-d
argument is missing. Only the third case is giving correct output.The bug appears to be that the unparser is skipping
Required = true
arguments, arguments with value equal toDefault = {value}
and arguments with value equal todefault(typeof(argument))
.The correct behaviour would be to only skip arguments that do not have
Required = true
and whose value equals the value specified inDefault = {value}
.The expected console output would be
These command lines would then correctly round trip parse/unparse.
The text was updated successfully, but these errors were encountered: