commandlineparser / commandlineparser/commandline

OptionAttribute Default not respected in usage example

Offen
#806 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
4.8k
Forks
478
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.