Description
I'm very impressed with the expressiveness of the model binding infrastructure, but I'm looking for ways to detect and prevent drift between the command line options and the handler implementation type over time.
For example, I can use model binding to set up declarative association between an option named "--preserve-configuration" and property name on a complex handler type named "PreserveConfiguration". However, if I decide later to prefer the more concise form of "--preserve-config", the model binding infrastructure will simply ignore the new value and the end result is that "PreserveConfiguration" will always be false. This can lead to very subtle bugs over time as the CLI interface and underlying handler types drift apart.
I've love to able to do something like this:
CommandHandler.Create(
async (InvocationContext context, MyLibraryHandler handler, IConsole console, CancellationToken ct) =>
{
// Throws if there are any values in the ParseResult that haven't been consumed by the model binder
context.ValidateStrictModelBinding();
MyLibraryResult result = await handler.RunAsync();
console.Out.Write(result.ToString());
});
The tricky part seems to be getting the layering right between validation and invocation, as throwing an exception directly from the handler delegate like I'm implying above seems less elegant than it could be.