recrownedgtk/RecrownedAthenaeum.ConsoleTools/CommandProcessor/HelpCommand.cs

57 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace RecrownedAthenaeum.Tools.CommandProcessor
{
internal class HelpCommand : EngineCommand
{
CommandEngine commandEngine;
public HelpCommand(CommandEngine commandEngine) : base("help")
{
this.commandEngine = commandEngine;
}
public override string Help(string argument)
{
return "Prints this.";
}
public override void Run(string[] arguments)
{
if (arguments != null)
{
if (commandEngine.ContainsCommand(arguments[0]))
{
ConsoleUtilities.WriteWrappedLine(commandEngine.GetCommand(arguments[0]).Help(null));
} else
{
throw new ArgumentException(arguments[0] + " not a command. Type \"help\" for a list of commands.");
}
} else
{
ConsoleUtilities.WriteWrappedLine("Tools for RecrownedAthenaeum library. Possible commands are as follows:\n");
foreach (EngineCommand engineCommand in commandEngine.commands)
{
for (int i = 0; i < engineCommand.invokeStrings.Length; i++)
{
ConsoleUtilities.WriteWrapped(engineCommand.invokeStrings[i]);
if (i + 1 < engineCommand.invokeStrings.Length)
{
ConsoleUtilities.WriteWrapped(", ");
}
}
foreach (string name in engineCommand.invokeStrings)
{
}
ConsoleUtilities.WriteWrapped(" : ");
ConsoleUtilities.WriteWrapped(engineCommand.Help().Replace("\n", "\n\t"), true);
Console.WriteLine();
}
}
}
}
}