mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-20 05:48:14 +08:00
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:

committed by
Patrik Svensson

parent
0bbf9b81a9
commit
0ae419326d
37
src/Spectre.Console/Cli/Internal/Parsing/CommandTree.cs
Normal file
37
src/Spectre.Console/Cli/Internal/Parsing/CommandTree.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Cli.Internal
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user