commandlineparser / commandlineparser/commandline

OptionAttribute Default not respected in usage example

未关闭
#806 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C#
星标
4.8k
派生
478
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。