Using the most current version of the CommandLineParser library, and I have a handful of options. My goal is to edit an XML file with this command line application, though that will hopefully expand.
public class MyOptions
{
[Option('h', "sayhello")]
public string HelloMessage { get; set; }
[Option('v', "versioninfo")]
public string VersionInfo { get; set; }
[Option('c', "changenode")]
public string[] ChangeNode { get; set; }
[Option('g', "getnode")]
public string[] GetNode { get; set; }
}
When I debug the application in Visual Studio and pass it the following argument/value via Project Properties -> Debug -> Command line arguments:
--sayhello hello
The application throws an InvalidOperationException, saying that the sequence contains no elements. If I comment out the two options that are of type string[] (ChangeNode and GetNode) or change them to IEnumerable<string>, the program runs without issue, hitting the following code:
if (!string.IsNullOrEmpty(options.HelloMessage))
Console.WriteLine($"The message is: {options.HelloMessage}");
printing out:
The message is: hello
Changing the options that are of type string[] to List<string> or setting those options to Required = false still throw the same exception. I don't have any qualms about casting the IEnumerable to another collection for the logic dealing with those options, but I'm not sure if this is proper practice; how do I use arrays/collections with CommandLineParser to avoid this? The documentation is very basic and doesn't go into a lot of detail about much of how the library works outside of a few "Quick Start" examples.