diff --git a/RecrownedGTK.Tools/CommandProcessor/EngineCommand.cs b/RecrownedGTK.Tools/CommandProcessor/EngineCommand.cs index bf58120..7d861a9 100644 --- a/RecrownedGTK.Tools/CommandProcessor/EngineCommand.cs +++ b/RecrownedGTK.Tools/CommandProcessor/EngineCommand.cs @@ -21,8 +21,10 @@ namespace RecrownedGTK.Tools.CommandProcessor protected EngineCommandArgument[] commandArguments; protected string help; - public EngineCommand(params string[] invokeStrings) + public EngineCommand(string help, params string[] invokeStrings) { + this.help = help ?? throw new ArgumentNullException(); + this.invokeStrings = invokeStrings ?? throw new ArgumentNullException(); for (int i = 0; i < invokeStrings.Length; i++) { if (invokeStrings[i].Contains(" ")) { @@ -92,23 +94,25 @@ namespace RecrownedGTK.Tools.CommandProcessor /// The argument to find the index of. /// The array containing all arguments. /// The index or throws argument exception if it doesn't exist. - public int IndexOfArgument(string argument, string[] arguments) + public static int IndexOfArgument(string argument, string[] arguments) { - if (arguments != null) + if (argument == null) throw new ArgumentNullException("Parameter \"argument\" is null."); + if (arguments == null) throw new ArgumentNullException("Parameter \"arguments\" is null."); + for (int i = 0; i < arguments.Length; i++) { - for (int i = 0; i < arguments.Length; i++) + if (arguments[i] == argument) { - if (arguments[i] == argument) - { - return i; - } + return i; } } - throw new ArgumentException("Expected argument " + argument + " is missing. Type \"help\" for more information."); + throw new ArgumentException(String.Format("The argument \"{0}\" doesn't exist in the given array of arguments.", argument)); } - public bool HasArgument(string argument, string[] arguments) + public static bool HasArgument(string argument, string[] arguments) { + if (argument == null) throw new ArgumentNullException("Parameter \"argument\" is null."); + if (arguments == null) throw new ArgumentNullException("Parameter \"arguments\" is null."); + try { IndexOfArgument(argument, arguments); @@ -120,7 +124,7 @@ namespace RecrownedGTK.Tools.CommandProcessor return true; } - public bool HasArgument(EngineCommandArgument argument, string[] arguments) + public static bool HasArgument(EngineCommandArgument argument, string[] arguments) { return HasArgument(argument.invokeString, arguments); } @@ -131,7 +135,7 @@ namespace RecrownedGTK.Tools.CommandProcessor /// The argument to find the index of. /// The array containing all arguments. /// The index or throws argument exception if it doesn't exist. - public int IndexOfArgumentIn(EngineCommandArgument argument, string[] arguments) + public static int IndexOfArgument(EngineCommandArgument argument, string[] arguments) { return IndexOfArgument(argument.invokeString, arguments); } @@ -164,7 +168,7 @@ namespace RecrownedGTK.Tools.CommandProcessor if (commandArguments != null) { helpBuilder.AppendLine(); - helpBuilder.Append("Possible arguments are: "); + helpBuilder.Append("Possible arguments: "); for (int i = 0; i < commandArguments.Length; i++) { helpBuilder.Append(commandArguments[i].invokeString); @@ -179,7 +183,7 @@ namespace RecrownedGTK.Tools.CommandProcessor } } helpBuilder.Append('.'); - helpBuilder.AppendLine(" [* are required arguments.]"); + helpBuilder.AppendLine(" (* are required arguments.)"); } return helpBuilder.ToString(); }