Add ICommands.HasCommand() method so that we can detect whether a command has already been registered without needing to also run it
parent
f0853139d5
commit
9be935ac6d
|
@ -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,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)
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue