mirror of
https://github.com/Stone-Red-Code/Commander.NET.git
synced 2026-09-04 08:56:09 +02:00
Fix help text indentation
This commit is contained in:
+11
-12
@@ -4,19 +4,11 @@ namespace Commander_Net;
|
||||
|
||||
public class Command
|
||||
{
|
||||
internal readonly List<Command> subCommands = new();
|
||||
public string[] Identifiers { get; init; }
|
||||
public Func<string, CommandResult> Method { get; init; }
|
||||
public HelpText HelpText { get; init; }
|
||||
|
||||
internal readonly List<Command> subCommands = new();
|
||||
|
||||
internal Command(Func<string, CommandResult> method, HelpText description, string[] identifiers)
|
||||
{
|
||||
Method = method;
|
||||
HelpText = description;
|
||||
Identifiers = identifiers;
|
||||
}
|
||||
|
||||
public Command()
|
||||
{
|
||||
Identifiers = Array.Empty<string>();
|
||||
@@ -24,6 +16,13 @@ public class Command
|
||||
Method = new Func<string, CommandResult>((_) => CommandResult.Success());
|
||||
}
|
||||
|
||||
internal Command(Func<string, CommandResult> method, HelpText description, string[] identifiers)
|
||||
{
|
||||
Method = method;
|
||||
HelpText = description;
|
||||
Identifiers = identifiers;
|
||||
}
|
||||
|
||||
public Command Register(Action<string> 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();
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user