diff --git a/Commander.NET/Command.cs b/Commander.NET/Command.cs index 3afefd3..4ecdf09 100644 --- a/Commander.NET/Command.cs +++ b/Commander.NET/Command.cs @@ -4,19 +4,11 @@ namespace Commander_Net; public class Command { + internal readonly List subCommands = new(); public string[] Identifiers { get; init; } public Func Method { get; init; } public HelpText HelpText { get; init; } - internal readonly List subCommands = new(); - - internal Command(Func method, HelpText description, string[] identifiers) - { - Method = method; - HelpText = description; - Identifiers = identifiers; - } - public Command() { Identifiers = Array.Empty(); @@ -24,6 +16,13 @@ public class Command Method = new Func((_) => CommandResult.Success()); } + internal Command(Func method, HelpText description, string[] identifiers) + { + Method = method; + HelpText = description; + Identifiers = identifiers; + } + public Command Register(Action method, params string[] identifiers) { return Register(method, new HelpText(), identifiers); @@ -93,7 +92,7 @@ public class Command { string[] inputParts = input.Split(' '); - Command? command = subCommands.FirstOrDefault(command => command.Identifiers.Contains(inputParts[0])); + Command? command = subCommands.Find(command => command.Identifiers.Contains(inputParts[0])); if (command is not null) { @@ -110,7 +109,7 @@ public class Command } } - internal string GetHelp(string input) + internal string GetHelp(string input, int indentation = 2) { string[] inputParts = input.Split(' '); @@ -118,7 +117,7 @@ public class Command foreach (Command command in subCommands.Where(command => command.Identifiers.Contains(inputParts[0]) || string.IsNullOrWhiteSpace(input))) { - _ = helpText.Append($"{Environment.NewLine} {command.GetHelp(string.Join(' ', inputParts.Skip(1)))}"); + _ = helpText.Append($"{Environment.NewLine}{new string(' ', indentation)}{command.GetHelp(string.Join(' ', inputParts.Skip(1)), indentation + 2)}"); } return helpText.ToString(); diff --git a/Commander.NET/Commander.cs b/Commander.NET/Commander.cs index 950f13d..3ad7eff 100644 --- a/Commander.NET/Commander.cs +++ b/Commander.NET/Commander.cs @@ -60,7 +60,7 @@ public class Commander { string[] inputParts = input.Split(' '); - Command? command = commands.FirstOrDefault(command => command.Identifiers.Contains(inputParts[0])); + Command? command = commands.Find(command => command.Identifiers.Contains(inputParts[0])); if (command is null) { diff --git a/Commander.Test/Program.cs b/Commander.Test/Program.cs index 7000a67..454ae17 100644 --- a/Commander.Test/Program.cs +++ b/Commander.Test/Program.cs @@ -4,7 +4,8 @@ Console.WriteLine("Hello, World!"); Commander commander = new Commander(); Command sayCommand = commander.Register(HahaYes, "say", "yell"); -sayCommand.Register(HahaYesSub, "kek"); +Command kekCommand = sayCommand.Register(HahaYesSub, "kek"); +kekCommand.Register(HahaYesSub, "lol"); commander.Register(HahaNo, "scream", "yell"); commander.Register(Add, "add");