Arvo Bowen
Arvo Bowen

Reputation: 4929

CommandLineParser - Use the same switch/flag multiple times

Using the CommandLineParser NuGet, when I run my application with an option like this.

myapplication.exe --searchfolder "c:\my great path\"

How can I use that options more than once? For example, if I want to pass in two folders...

  1. "c:\my great path"
  2. "c:\my other great path"

Currently, I use it like this for the single path given...

if (options.Verbose)
{
    m_Verbose = true;
    Console.WriteLine("Verbose mode on.");
}

if (options.SearchFolder != null && options.SearchFolder != "")
{
  Console.WriteLine("Searching folder '{0}'...", options.SearchFolder);
}

Upvotes: 2

Views: 665

Answers (1)

Athanasios Kataras
Athanasios Kataras

Reputation: 26352

You might want to use something like this:

class Options
{
  [Option('r', "read", Required = true, HelpText = "Input files to be processed.")]
  public IEnumerable<string> InputFiles { get; set; }

Check the official net fiddle here: https://dotnetfiddle.net/wrcAxr for the IEnumerable usage.

Upvotes: 2

Related Questions