command-line-api
command-line-api copied to clipboard
(Small) API Suggestion: Make SetHandler return parent instance
At the moment, with the new API style the recommended approach is something like:
var subCommand = new Command("subcommand")
{
new Option<string>("-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<string>("-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<string>("-x"),
(string x) => {
//Do stuff
}
};
};