26 lines
791 B
C#
26 lines
791 B
C#
using System.Collections.Generic;
|
|
using Game.Features.Console.Contracts;
|
|
using Game.Features.Console.Domain;
|
|
|
|
namespace Game.Features.Console.Application;
|
|
|
|
public sealed class CommandExecute(ICommandRegistry registry)
|
|
{
|
|
public CommandResult Execute(string input)
|
|
{
|
|
if (!CommandLineParser.TryParse(input, out string name, out IReadOnlyList<string> arguments))
|
|
{
|
|
return CommandResult.Fail("No command entered.");
|
|
}
|
|
|
|
if (!registry.TryGet(name, out ICommand command))
|
|
{
|
|
return CommandResult.Fail($"Unknown command: {name}");
|
|
}
|
|
|
|
CommandResult result = CommandArgValidator.Validate(command.Args, arguments);
|
|
|
|
return !result.Success ? result : command.Execute(new CommandArgValues(arguments));
|
|
}
|
|
}
|