dotnet / dotnet/command-line-api
Please provide a Source Generator that generates an implementation of ICommandHandler.
- 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
Assessment
This issue has not been assessed yet.