recrownedathenaeum/RecrownedAthenaeum.Tools/CommandProcessor/Commands/HelpCommand.cs

54 lines
2.0 KiB
C#
Raw Normal View History

using System;
2018-12-09 20:27:31 +00:00
namespace RecrownedAthenaeum.Tools.CommandProcessor.Commands
{
internal class HelpCommand : EngineCommand
{
CommandEngine commandEngine;
public HelpCommand(CommandEngine commandEngine) : base("help")
{
this.commandEngine = commandEngine;
2018-12-29 00:52:52 +00:00
help = "help [command] [arg]";
}
public override void Run(string[] arguments)
{
if (arguments != null)
{
if (commandEngine.ContainsCommand(arguments[0]))
{
2018-12-09 07:23:18 +00:00
if (arguments.Length < 2) ConsoleUtilities.WriteWrappedLine(commandEngine.GetCommand(arguments[0]).Help(null));
2018-12-09 07:10:18 +00:00
for (int i = 1; i < arguments.Length; i++)
{
ConsoleUtilities.WriteWrappedLine(commandEngine.GetCommand(arguments[0]).Help(arguments[i]));
}
}
else
{
throw new ArgumentException(arguments[0] + " not a command. Type \"help\" for a list of commands.");
}
2018-12-09 07:10:18 +00:00
}
else
{
ConsoleUtilities.WriteWrappedLine("Tools for RecrownedAthenaeum library. Possible commands are as follows:\n");
foreach (EngineCommand engineCommand in commandEngine.commands)
{
2018-12-29 00:52:52 +00:00
for (int i = 0; i < engineCommand.InvokeStrings.Length; i++)
{
2018-12-29 00:52:52 +00:00
ConsoleUtilities.WriteWrapped(engineCommand.InvokeStrings[i]);
if (i + 1 < engineCommand.InvokeStrings.Length)
{
ConsoleUtilities.WriteWrapped(", ");
}
}
ConsoleUtilities.WriteWrapped(" : ");
ConsoleUtilities.WriteWrapped(engineCommand.Help().Replace("\n", "\n\t"), true);
2018-12-09 06:55:51 +00:00
Console.WriteLine("--------");
}
}
}
}
}