Command Line Parser Library parsing a List of Enums

Viewed 2887

I'm trying to get a list of enums as an option.

[OptionList('m', "modules", HelpText = "List of modules you are going to install or uninstall.")]
public List<RegistrationType> Modules { get; set; }

Unfortunately it expects it to be a list of strings. Any idea on how to make it work as documentation of the lib is a bit short.

Thanks

2 Answers

As of Nov 2018, there is a support for IEnumerable<TEnum> (package version 2.3.0):

[Option('m', "modules", Separator = ',', HelpText = "List of modules...")]
public IEnumerable<RegistrationType> Modules { get; set; }

Sample parse (has changed since the question was asked):

static void Main(string[] args)
{
    Parser.Default.ParseArguments<Options>(args)
        .WithParsed(options => ...)
}

Sample command line:

myProject.exe -m RegistrationType1,RegistrationType2
Related