0

I've got this RootCommand:

var rootCommand = new RootCommand()
            {
                new Argument<string>("search","string to search for")
                ,new Option<string>(new []{"--path","-p"},getDefaultValue:()=>Directory.GetCurrentDirectory(),"path where to search")
                ,new Option<string[]>(new []{"-f","--files"},"file pattern to match to search in"){ Argument=new Argument<string[]>(getDefaultValue:()=>new[]{"*.*"}){Arity=ArgumentArity.ZeroOrMore} }
            };

the option -f is supposed to take zero or more values, but in the handler defined as below:

rootCommand.Handler= CommandHandler.Create<string,string,string[]>(async (search,path,filepattern)=> {

filepattern is always null, even if I call with, for instance -f *.cs. What I'm missing?

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115

1 Answers1

1

I believe the issue was that the argument names don't match the option names

Microsoft Docs say:

Camel casing on Main’s parameter names is converted to Posix-style argument names (that is, xCropSize translates to --x-crop-size on the command line).

So this Should work:

rootCommand.Handler= CommandHandler.Create<string,string,string[]>(async (search,path,files)=> {
Digital Coyote
  • 326
  • 2
  • 12