in src/Microsoft.Atlas.CommandLine/CommandLineApplicationExtensions.cs [76:100]
public static void OnExecute<TCommand>(this CommandLineApplication app, Func<TCommand, int> onExecute)
{
app.OnExecute(() =>
{
var command = GetServiceProvider(app).GetRequiredService<TCommand>();
var typeInfo = command.GetType().GetTypeInfo();
foreach (var property in typeInfo.GetProperties().Where(prop => prop.PropertyType == typeof(CommandOption)))
{
var commandOption = GetAllOptions(app).FirstOrDefault(option => Match(property, option));
if (commandOption != null)
{
property.SetValue(command, commandOption);
}
}
foreach (var property in typeInfo.GetProperties().Where(prop => prop.PropertyType == typeof(CommandArgument)))
{
var commandArgument = GetAllArguments(app).FirstOrDefault(argument => Match(property, argument));
if (commandArgument != null)
{
property.SetValue(command, commandArgument);
}
}
return onExecute(command);
});
}