Files
spectre.console/src/Spectre.Console/Cli/Internal/Parsing/CommandTree.cs
Patrik Svensson 52c1d9122b Add global usings (#668)
* Use global usings

* Fix namespace declarations for test projects
2021-12-23 16:50:31 +01:00

34 lines
959 B
C#

namespace Spectre.Console.Cli;
internal sealed class CommandTree
{
public CommandInfo Command { get; }
public List<MappedCommandParameter> Mapped { get; }
public List<CommandParameter> Unmapped { get; }
public CommandTree? Parent { get; }
public CommandTree? Next { get; set; }
public bool ShowHelp { get; set; }
public CommandTree(CommandTree? parent, CommandInfo command)
{
Parent = parent;
Command = command;
Mapped = new List<MappedCommandParameter>();
Unmapped = new List<CommandParameter>();
}
public ICommand CreateCommand(ITypeResolver resolver)
{
if (Command.Delegate != null)
{
return new DelegateCommand(Command.Delegate);
}
if (resolver.Resolve(Command.CommandType) is ICommand command)
{
return command;
}
throw CommandParseException.CouldNotCreateCommand(Command.CommandType);
}
}