Skip to content

[Docs] Specify in docs that command handler Create methods' parameters must match options #1343

Open
@j0shuams

Description

@j0shuams

I spent a while trying to figure out why my options were not binding, even though I was doing everything the docs said to.
However, I was doing essentially what the docs said.

static async Task Main(string[] args)
{
    var rootCommand = new RootCommand
    {
      new Option
      (
         name: "--target",
         argumentType: typeof(string), 
         arity: ArgumentArity.ExactlyOne 
       )
     };

    rootCommand.Handler = CommandHandler.Create<string>(Foo);
    await rootCommand.InvokeAsync(args);            
}       
        
private static int Foo(string targetAssembly) // <-- mistake!
{
    Console.WriteLine($"--target = {targetAssembly}");
}

My mistake was just in the name of the parameter, and I didn't see this mentioned in the docs anywhere. I would like to suggest adding it to the first section of the "Model bindings" page :)

This other issue is how I figured out my problem, FWIW: #1326

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions