Add Spectre.Cli to Spectre.Console

* Renames Spectre.Cli to Spectre.Console.Cli.
* Now uses Verify with Spectre.Console.Cli tests.
* Removes some duplicate definitions.

Closes #168
This commit is contained in:
Patrik Svensson
2020-12-23 10:41:29 +01:00
committed by Patrik Svensson
parent 0bbf9b81a9
commit 0ae419326d
361 changed files with 13934 additions and 604 deletions

View File

@ -0,0 +1,31 @@
using System;
namespace Spectre.Console.Cli.Internal
{
internal static class CommandBinder
{
public static CommandSettings Bind(CommandTree? tree, Type settingsType, ITypeResolver resolver)
{
var lookup = CommandValueResolver.GetParameterValues(tree, resolver);
// Got a constructor with at least one name corresponding to a settings?
foreach (var constructor in settingsType.GetConstructors())
{
var parameters = constructor.GetParameters();
if (parameters.Length > 0)
{
foreach (var parameter in parameters)
{
if (lookup.HasParameterWithName(parameter?.Name))
{
// Use constructor injection.
return CommandConstructorBinder.CreateSettings(lookup, constructor, resolver);
}
}
}
}
return CommandPropertyBinder.CreateSettings(lookup, settingsType, resolver);
}
}
}