using System; using System.Collections.Generic; using System.Text; namespace RecrownedAthenaeum.Tools.CommandProcessor { public abstract class EngineCommand { bool CaseSensitiveName = false; /// /// the words a user can type that will invoke this command. /// public string[] invokeStrings; public EngineCommand(params string[] invokeStrings) { this.invokeStrings = invokeStrings ?? throw new ArgumentNullException(); } /// /// Whether or not this command should be invoked given the string. /// /// The string that acts as the command. /// whether or not this command is invoked. public bool IsInvoked(string command) { if (!CaseSensitiveName) command = command.ToLower(); for (int i = 0; i < invokeStrings.Length; i++) { if (!CaseSensitiveName) { if (invokeStrings[i].ToLower() == command) return true; } else { if (invokeStrings[i] == command) return true; } } return false; } /// /// Runs the command. /// /// arguments to be used. May be null. public virtual void Run(string[] arguments = null) { } /// /// Returns the help for the given argument for this command. If no argument is defined, general help for the command should be given. /// If no argument is given (null), then returns overall help statement. /// /// The argument the help string is for. Can be null for overall command help. /// The text to help understand the argument. public virtual string Help(string argument = null) { return "This command doesn't define a help string. Shame on it."; } } }