Add ICommands.HasCommand() method so that we can detect whether a command has already been registered without needing to also run it

bullet-2.82
Justin Clark-Casey (justincc) 2014-07-18 22:27:39 +01:00
parent f0853139d5
commit 9be935ac6d
4 changed files with 37 additions and 18 deletions

View File

@ -424,9 +424,9 @@ namespace OpenSim.Framework.Console
return new string[] { new List<string>(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<string, object> current = tree;
@ -458,7 +458,7 @@ namespace OpenSim.Framework.Console
}
else if (found.Count > 0)
{
return new string[0];
return null;
}
else
{
@ -467,10 +467,28 @@ namespace OpenSim.Framework.Console
}
if (current.ContainsKey(String.Empty))
return (CommandInfo)current[String.Empty];
return null;
}
public bool HasCommand(string command)
{
CommandInfo ci = (CommandInfo)current[String.Empty];
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)
{
if (fn != null)
@ -478,10 +496,8 @@ namespace OpenSim.Framework.Console
else
return new string[0];
}
return result;
}
return new string[0];
return result;
}
public XmlElement GetXml(XmlDocument doc)

View File

@ -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; }
}

View File

@ -67,9 +67,11 @@ namespace OpenSim.Framework
string help, string longhelp, string descriptivehelp,
CommandDelegate fn);
string[] FindNextOption(string[] cmd, bool term);
bool HasCommand(string command);
string[] Resolve(string[] cmd);
string[] FindNextOption(string[] command, bool term);
string[] Resolve(string[] command);
XmlElement GetXml(XmlDocument doc);
}

View File

@ -96,7 +96,7 @@ namespace OpenSim.Services.GridService
// has an identically named command
//
// XXX: We're relying on the OpenSimulator version being registered first, which is not well defined.
if (MainConsole.Instance.Commands.Resolve(new string[] { "show", "regions" }).Length == 0)
if (!MainConsole.Instance.Commands.HasCommand("show regions"))
MainConsole.Instance.Commands.AddCommand("Regions", true,
"show regions",
"show regions",