commandlineparser / commandlineparser/commandline

OptionAttribute Default not respected in usage example

Open
#806 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.8k
Forks
478
PR merge metrics
No merged PRs in 30d

Description

I'm using CommandLineParser version 2.8.0. The usage example seems to use `default(MyEnum)` instead of the OptionAttribute Default or even `(new MyOptions()).Enum` as the default value. A workaround is to reorder the enum values so `default(MyEnum)` and Default are the same.

```c#
enum MyEnum
{
A,
B,
C,
}

class MyOptions
{
[Option('e', "enum", Default = MyEnum.B)]
MyEnum Enum { get; init; } = MyEnum.B;

[Usage]
static IEnumerable Examples
{
get
{
yield return new Example("Do stuff", new MyOptions { Enum = MyEnum.A });
yield return new Example("Do stuff", new MyOptions { });
yield return new Example("Do stuff", new MyOptions { Enum = MyEnum.C });
}
}
}
```

**Expected usage examples:**
myprogram --enum A
myprogram
myprogram --enum C

**Actual usage examples:**
myprogram
myprogram --enum B
myprogram --enum C

Note that if Enum is not initialized to MyEnum.B in MyOptions, then the actual usage examples become:
myprogram
myprogram
myprogram --enum C

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.