2018-12-09 06:51:33 +00:00
using System ;
using System.Collections.Generic ;
using System.Text ;
namespace RecrownedAthenaeum.Tools.CommandProcessor
{
public abstract class EngineCommand
{
bool CaseSensitiveName = false ;
/// <summary>
/// the words a user can type that will invoke this command.
/// </summary>
public string [ ] invokeStrings ;
public EngineCommand ( params string [ ] invokeStrings )
{
this . invokeStrings = invokeStrings ? ? throw new ArgumentNullException ( ) ;
}
/// <summary>
/// Whether or not this command should be invoked given the string.
/// </summary>
/// <param name="command">The string that acts as the command.</param>
/// <returns>whether or not this command is invoked.</returns>
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 ;
}
/// <summary>
/// Runs the command.
/// </summary>
/// <param name="arguments">arguments to be used. May be null.</param>
public virtual void Run ( string [ ] arguments = null )
{
}
/// <summary>
/// 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.
2018-12-09 07:09:50 +00:00
/// Overall help should list possible arguments for user to use "help [command] [arg]" format.
/// Arguments can then be separately returned from help as the help command will pass in the argument the user requests to see in detail in the parameter.
2018-12-09 06:51:33 +00:00
/// </summary>
/// <param name="argument">The argument the help string is for. Can be null for overall command help.</param>
/// <returns>The text to help understand the argument.</returns>
public virtual string Help ( string argument = null )
{
return "This command doesn't define a help string. Shame on it." ;
}
}
}