dotnet / dotnet/command-line-api

Please provide a Source Generator that generates an implementation of ICommandHandler.

Open
#1,980 0 comments 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 would like a Source Generator that supports implementing ICommandHandler like DragonFruit.

For example, for the following code,

```cs
partial class CommandHandler
{
[CommandHandler]
Task Handle(
int foo)
{
// command handling
}
}
```

generates following implementation.

```cs
partial class CommandHandler : ICommandHandler
{
public Task InvokeAsync(InvocationContext context)
{
var fooOption = context.ParseResult.CommandResult.Command.Options
.SingleOrDefault(static option => option.Name == "foo");

var fooValue = context.ParseResult.GetValueForOption(fooOption);

return this.Handle(fooValue);
}
}
```

The above code is for a very simple case; more considerations are needed for what actually works.

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.