dotnet / dotnet/command-line-api
(Small) API Suggestion: Make SetHandler return parent instance
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
At the moment, with the new API style the recommended approach is something like:
```
var subCommand = new Command("subcommand")
{
new Option("-x")
};
var rootCommand = new RootCommand
{
subCommand
};
subCommand.SetHandler(string x => {
//Do stuff
});
```
But this can be quite terse, at the moment the `SetHandler` methods return `void` - if it could instead return the instance of the command the API comes alot more fluent and shorter:
```
var rootCommand = new RootCommand
{
new Command("subcommand")
{
new Option("-x")
}
.SetHandler((string x) => {
//Do stuff
});
};
```
Or potentially extend the `Add` methods on `Command` to include the `Func<>`/Command handler
```
var rootCommand = new RootCommand
{
new Command("subcommand")
{
new Option("-x"),
(string x) => {
//Do stuff
}
};
};
```
Contributor guide
Assessment
This issue has not been assessed yet.