commandlineparser / commandlineparser/commandline

OptionAttribute Default not respected in usage example

オープン
#806 コメント 0 件 リアクション 0 件 担当者 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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

まず、MyOptions クラス、その OptionAttribute Default、および [Usage] Examples エントリーポイントを使用して、CommandLineParser 2.8.0 で問題を再現します。Usage の例によってオプションを出力するかどうかがどのように決定されるかを追跡し、その後、例が期待どおりに A、オプションなし、C を生成することを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp
領域
cli
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。