commandlineparser / commandlineparser/commandline

OptionAttribute Default not respected in usage example

Aperta
#806 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C#
Stelle
4.8k
Fork
478
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.