dotnet / dotnet/command-line-api

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

Open
#1,343 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

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(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 ](https://github.com/dotnet/command-line-api/blob/main/docs/model-binding.md#more-complex-types) :)

This other issue is how I figured out my problem, FWIW: https://github.com/dotnet/command-line-api/issues/1326

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.