gsscoder/commandline

Enum Parsing Is Failing

Stoldney opened this issue · 2 comments

I am trying to parse out an enum, following the guide on the "Mapping Properties to Optopns" page, but I am getting a bad format error.

Here is my class:

public enum EnvironmentType { Dev, Prod }

public class Options
{
    [Option("environment")]
    public EnvironementType Environment {get;set;}
}

Here is how I am running the console app:

app.exe --environment dev

ERROR(S):
Option 'environment' is defined with a bad format.

No matter how I try passing the enum (dev, DEV, 'dev', "dev", etc) it fails with the bad format exception.

I am using Nuget package Latest Stable 2.3.0. I have also tried packages going back to 1.9, to no avail.

Am I missing something?

nemec commented

Try Dev, since that's how it's capitalized in your enum :)

You can make it all case insensitive by configuring a new parser:

var parser = new Parser(conf =>
{
    conf.CaseInsensitiveEnumValues = true;
});
parser.ParseArguments<Options>(...);

P.S. this repository is closed. Please open any further issues at https://github.com/commandlineparser/commandline

That was indeed the issue. Thanks for the assistance.

You should consider updating the enum parsing documentation in the wiki on this repo and move it to the new one:
https://github.com/gsscoder/commandline/wiki/Mapping-Properties-To-Options

That states its case insensitive out of the box.