feat: add console command framework
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user