noz-cli/NozCli/Repl/CommandRegistry.cs
2026-05-16 19:25:39 +02:00

34 lines
878 B
C#

using NozCli.Commands;
namespace NozCli.Repl;
public class CommandRegistry
{
private readonly Dictionary<string, ICommand> _map;
public IReadOnlyList<ICommand> All { get; }
public CommandRegistry()
{
var list = new List<ICommand>
{
new LsCommand(),
new CdCommand(),
new CatCommand(),
new EditCommand(),
new PushCommand(),
new SyncCommand(),
new StatusCommand(),
new RmCommand(),
};
// HelpCommand gets the full list so it can print them all
list.Add(new HelpCommand(list));
All = list.AsReadOnly();
_map = list.ToDictionary(c => c.Name, StringComparer.OrdinalIgnoreCase);
}
public ICommand? Find(string name) => _map.GetValueOrDefault(name);
public IEnumerable<string> Names => _map.Keys;
}