简体   繁体   中英

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);
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM