-
Notifications
You must be signed in to change notification settings - Fork 481
Usage Example only treats an Option of type Enum with inner value of 0 as default, regardless of Enum value chosen for Example (demo repo provided) #457
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
Comments
Agreed, it is a big problem and more simpler : ENUM with value 0 just doesn't display in USAGE. In order to see enum in usage, they must start with 1, but it's bad, as it force us to change the enum codes. Enum that start with 0 are not display in USAGE. Please dev, fix it, it's very annoying and it's like that since a long time. |
@jdmallen , @obewan
by applying this Rule:
|
It's fixed in v2.8.0 There is a new feature to skip the default values for enum. Modify the code and use the [Verb("default")]
public class DefaultOptions : IOptions
{
public string RequiredOption { get; set; }
public EnumOptions FakeOption { get; set; }
[Usage(ApplicationAlias = "CommandLineParserUsageBug.exe")]
public static IEnumerable<Example> Examples
{
get
{
var formatStyle = new List<UnParserSettings> { new UnParserSettings { SkipDefault = true } };
yield return new Example(
"Run with enum option One selected",
formatStyle,
new DefaultOptions
{
FakeOption = EnumOptions.OptionOne
});
yield return new Example(
"Run with enum option Two selected",
formatStyle,
new DefaultOptions
{
FakeOption = EnumOptions.OptionTwo
}
);
}
} for the enum, public enum EnumOptions
{
OptionOne=1,
OptionTwo
} you get the help:
|
Please clone and execute this repo to see the problem in action.
This is similar to, but distinct from, issue #379.
Steps to re-pro
Verb
attribute.Option
of typeEnum
with at least two values, each with a default (not assigned) inner value (i.e. 0 and 1, respectively).Default
property of theOption
to an enum value other than the one assigned to 0.Usage
section with twoExample
s, one with the firstEnum
option chosen, another with any otherEnum
option chosen.Expected behavior
Where the usage
Example
chooses the default value for theOption
, theOption
is omitted from the usage as it is redundant. If a different value from default is chosen for the Option, the specified option is displayed in the usage, since it's different.Actual behavior
Only when the Enum inner value for the option is 0 will the usage treat it as the default value and omit it from the usage, regardless of whether the default value is chosen for a specific example.
Try changing the
Enum
such that each value is assigned something other than 0, like 1 and 2, then re-run the program with usage showing.You'll notice that the option is always displayed, regardless of whether the chosen option matches the default.
It appears that when the Enum type is used for an Option, the Default for that option is not respected when it comes to displaying an Example under Usage on the help screen.
The text was updated successfully, but these errors were encountered: