From 9be935ac6d74fd3b8c0c95058a575e400dd916a4 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 18 Jul 2014 22:27:39 +0100 Subject: Add ICommands.HasCommand() method so that we can detect whether a command has already been registered without needing to also run it --- OpenSim/Framework/Console/CommandConsole.cs | 46 +++++++++++++++++++---------- OpenSim/Framework/Console/MockConsole.cs | 1 + 2 files changed, 32 insertions(+), 15 deletions(-) (limited to 'OpenSim/Framework/Console') diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs index b9f402a..0f68afe 100644 --- a/OpenSim/Framework/Console/CommandConsole.cs +++ b/OpenSim/Framework/Console/CommandConsole.cs @@ -424,9 +424,9 @@ namespace OpenSim.Framework.Console return new string[] { new List(current.Keys)[0] }; } - public string[] Resolve(string[] cmd) + private CommandInfo ResolveCommand(string[] cmd, out string[] result) { - string[] result = cmd; + result = cmd; int index = -1; Dictionary current = tree; @@ -458,7 +458,7 @@ namespace OpenSim.Framework.Console } else if (found.Count > 0) { - return new string[0]; + return null; } else { @@ -467,21 +467,37 @@ namespace OpenSim.Framework.Console } if (current.ContainsKey(String.Empty)) + return (CommandInfo)current[String.Empty]; + + return null; + } + + public bool HasCommand(string command) + { + string[] result; + return ResolveCommand(Parser.Parse(command), out result) != null; + } + + public string[] Resolve(string[] cmd) + { + string[] result; + CommandInfo ci = ResolveCommand(cmd, out result); + + if (ci == null) + return new string[0]; + + if (ci.fn.Count == 0) + return new string[0]; + + foreach (CommandDelegate fn in ci.fn) { - CommandInfo ci = (CommandInfo)current[String.Empty]; - if (ci.fn.Count == 0) + if (fn != null) + fn(ci.module, result); + else return new string[0]; - foreach (CommandDelegate fn in ci.fn) - { - if (fn != null) - fn(ci.module, result); - else - return new string[0]; - } - return result; } - - return new string[0]; + + return result; } public XmlElement GetXml(XmlDocument doc) diff --git a/OpenSim/Framework/Console/MockConsole.cs b/OpenSim/Framework/Console/MockConsole.cs index 18a48bd..1a142df 100644 --- a/OpenSim/Framework/Console/MockConsole.cs +++ b/OpenSim/Framework/Console/MockConsole.cs @@ -82,6 +82,7 @@ namespace OpenSim.Framework.Console public void AddCommand(string module, bool shared, string command, string help, string longhelp, CommandDelegate fn) {} public void AddCommand(string module, bool shared, string command, string help, string longhelp, string descriptivehelp, CommandDelegate fn) {} public string[] FindNextOption(string[] cmd, bool term) { return null; } + public bool HasCommand(string cmd) { return false; } public string[] Resolve(string[] cmd) { return null; } public XmlElement GetXml(XmlDocument doc) { return null; } } -- cgit v1.1