using System; using System.Collections.Generic; using System.Runtime.CompilerServices; public class CommandInterpreter { public readonly Dictionary _commands = new(); public CommandInterpreter() { RegisterCommand(new GreetCommand()); RegisterCommand(new HelpCommand(this)); } public void RegisterCommand(ICommand command) { _commands[command.Name.ToLower()] = command; } public void Execute(string input) { string[] parts = input.Split(" ", StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 0) return; string commandName = parts[0].ToLower(); string[] args = parts.Length > 1 ? parts[1..] : new string[0]; if (_commands.TryGetValue(commandName, out var command)) { command.Execute(args); } else { Console.WriteLine("Err - uknown Command : '{commandName}'. Type help For a list of commands"); } } public IEnumerable GetAllCommands() { return _commands.Values; } }