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] };
|
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;
|
int index = -1;
|
||||||
|
|
||||||
Dictionary<string, object> current = tree;
|
Dictionary<string, object> current = tree;
|
||||||
|
@ -458,7 +458,7 @@ namespace OpenSim.Framework.Console
|
||||||
}
|
}
|
||||||
else if (found.Count > 0)
|
else if (found.Count > 0)
|
||||||
{
|
{
|
||||||
return new string[0];
|
return null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -467,21 +467,37 @@ namespace OpenSim.Framework.Console
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current.ContainsKey(String.Empty))
|
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 (fn != null)
|
||||||
if (ci.fn.Count == 0)
|
fn(ci.module, result);
|
||||||
|
else
|
||||||
return new string[0];
|
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)
|
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, CommandDelegate fn) {}
|
||||||
public void AddCommand(string module, bool shared, string command, string help, string longhelp, string descriptivehelp, 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 string[] FindNextOption(string[] cmd, bool term) { return null; }
|
||||||
|
public bool HasCommand(string cmd) { return false; }
|
||||||
public string[] Resolve(string[] cmd) { return null; }
|
public string[] Resolve(string[] cmd) { return null; }
|
||||||
public XmlElement GetXml(XmlDocument doc) { return null; }
|
public XmlElement GetXml(XmlDocument doc) { return null; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,9 +67,11 @@ namespace OpenSim.Framework
|
||||||
string help, string longhelp, string descriptivehelp,
|
string help, string longhelp, string descriptivehelp,
|
||||||
CommandDelegate fn);
|
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);
|
XmlElement GetXml(XmlDocument doc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace OpenSim.Services.GridService
|
||||||
// has an identically named command
|
// has an identically named command
|
||||||
//
|
//
|
||||||
// XXX: We're relying on the OpenSimulator version being registered first, which is not well defined.
|
// 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,
|
MainConsole.Instance.Commands.AddCommand("Regions", true,
|
||||||
"show regions",
|
"show regions",
|
||||||
"show regions",
|
"show regions",
|
||||||
|
|
Loading…
Reference in New Issue