using System; namespace RecrownedGTK.Tools.CommandProcessor.Commands { public class HelpCommand : EngineCommand { CommandEngine commandEngine; public HelpCommand(CommandEngine commandEngine) : base("help") { this.commandEngine = commandEngine; help = "help [command] [arg]"; } public override void Run(IUserInput userInput, IUserOutput userOutput, string[] arguments) { if (arguments != null) { if (commandEngine.ContainsCommand(arguments[0])) { if (arguments.Length < 2) userOutput.WrappedOutput(commandEngine.GetCommand(arguments[0]).Help(null)); for (int i = 1; i < arguments.Length; i++) { userOutput.WrappedOutput(commandEngine.GetCommand(arguments[0]).Help(arguments[i])); } } else { throw new ArgumentException(arguments[0] + " not a command. Type \"help\" for a list of commands."); } } else { userOutput.WrappedOutput("Tools for RecrownedGTK library. Possible commands are as follows:\n"); foreach (EngineCommand engineCommand in commandEngine.commands) { for (int i = 0; i < engineCommand.InvokeStrings.Length; i++) { userOutput.WrappedOutput(engineCommand.InvokeStrings[i]); if (i + 1 < engineCommand.InvokeStrings.Length) { userOutput.WrappedOutput(", "); } } userOutput.WrappedOutput(" : "); userOutput.WrappedOutput(engineCommand.Help().Replace("\n", "\n\t")); userOutput.WrappedOutput("\n"); userOutput.Output("--------"); } } } } }