aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-07-18 22:27:39 +0100
committerJustin Clark-Casey (justincc)2014-07-18 22:27:39 +0100
commit9be935ac6d74fd3b8c0c95058a575e400dd916a4 (patch)
treee3fb5cc9f75bb555f879dcfda5a496eaf4a2594b
parentrefactor: slightly adjust some code in ODECharacter.Move() to eliminate a con... (diff)
downloadopensim-SC-9be935ac6d74fd3b8c0c95058a575e400dd916a4.zip
opensim-SC-9be935ac6d74fd3b8c0c95058a575e400dd916a4.tar.gz
opensim-SC-9be935ac6d74fd3b8c0c95058a575e400dd916a4.tar.bz2
opensim-SC-9be935ac6d74fd3b8c0c95058a575e400dd916a4.tar.xz
Add ICommands.HasCommand() method so that we can detect whether a command has already been registered without needing to also run it
-rw-r--r--OpenSim/Framework/Console/CommandConsole.cs46
-rw-r--r--OpenSim/Framework/Console/MockConsole.cs1
-rw-r--r--OpenSim/Framework/ICommandConsole.cs6
-rw-r--r--OpenSim/Services/GridService/GridService.cs2
4 files changed, 37 insertions, 18 deletions
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
424 return new string[] { new List<string>(current.Keys)[0] }; 424 return new string[] { new List<string>(current.Keys)[0] };
425 } 425 }
426 426
427 public string[] Resolve(string[] cmd) 427 private CommandInfo ResolveCommand(string[] cmd, out string[] result)
428 { 428 {
429 string[] result = cmd; 429 result = cmd;
430 int index = -1; 430 int index = -1;
431 431
432 Dictionary<string, object> current = tree; 432 Dictionary<string, object> current = tree;
@@ -458,7 +458,7 @@ namespace OpenSim.Framework.Console
458 } 458 }
459 else if (found.Count > 0) 459 else if (found.Count > 0)
460 { 460 {
461 return new string[0]; 461 return null;
462 } 462 }
463 else 463 else
464 { 464 {
@@ -467,21 +467,37 @@ namespace OpenSim.Framework.Console
467 } 467 }
468 468
469 if (current.ContainsKey(String.Empty)) 469 if (current.ContainsKey(String.Empty))
470 return (CommandInfo)current[String.Empty];
471
472 return null;
473 }
474
475 public bool HasCommand(string command)
476 {
477 string[] result;
478 return ResolveCommand(Parser.Parse(command), out result) != null;
479 }
480
481 public string[] Resolve(string[] cmd)
482 {
483 string[] result;
484 CommandInfo ci = ResolveCommand(cmd, out result);
485
486 if (ci == null)
487 return new string[0];
488
489 if (ci.fn.Count == 0)
490 return new string[0];
491
492 foreach (CommandDelegate fn in ci.fn)
470 { 493 {
471 CommandInfo ci = (CommandInfo)current[String.Empty]; 494 if (fn != null)
472 if (ci.fn.Count == 0) 495 fn(ci.module, result);
496 else
473 return new string[0]; 497 return new string[0];
474 foreach (CommandDelegate fn in ci.fn)
475 {
476 if (fn != null)
477 fn(ci.module, result);
478 else
479 return new string[0];
480 }
481 return result;
482 } 498 }
483 499
484 return new string[0]; 500 return result;
485 } 501 }
486 502
487 public XmlElement GetXml(XmlDocument doc) 503 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
82 public void AddCommand(string module, bool shared, string command, string help, string longhelp, CommandDelegate fn) {} 82 public void AddCommand(string module, bool shared, string command, string help, string longhelp, CommandDelegate fn) {}
83 public void AddCommand(string module, bool shared, string command, string help, string longhelp, string descriptivehelp, CommandDelegate fn) {} 83 public void AddCommand(string module, bool shared, string command, string help, string longhelp, string descriptivehelp, CommandDelegate fn) {}
84 public string[] FindNextOption(string[] cmd, bool term) { return null; } 84 public string[] FindNextOption(string[] cmd, bool term) { return null; }
85 public bool HasCommand(string cmd) { return false; }
85 public string[] Resolve(string[] cmd) { return null; } 86 public string[] Resolve(string[] cmd) { return null; }
86 public XmlElement GetXml(XmlDocument doc) { return null; } 87 public XmlElement GetXml(XmlDocument doc) { return null; }
87 } 88 }
diff --git a/OpenSim/Framework/ICommandConsole.cs b/OpenSim/Framework/ICommandConsole.cs
index a6573f8..c6c6d40 100644
--- a/OpenSim/Framework/ICommandConsole.cs
+++ b/OpenSim/Framework/ICommandConsole.cs
@@ -67,9 +67,11 @@ namespace OpenSim.Framework
67 string help, string longhelp, string descriptivehelp, 67 string help, string longhelp, string descriptivehelp,
68 CommandDelegate fn); 68 CommandDelegate fn);
69 69
70 string[] FindNextOption(string[] cmd, bool term); 70 bool HasCommand(string command);
71 71
72 string[] Resolve(string[] cmd); 72 string[] FindNextOption(string[] command, bool term);
73
74 string[] Resolve(string[] command);
73 75
74 XmlElement GetXml(XmlDocument doc); 76 XmlElement GetXml(XmlDocument doc);
75 } 77 }
diff --git a/OpenSim/Services/GridService/GridService.cs b/OpenSim/Services/GridService/GridService.cs
index 02ed90e..aa19fc7 100644
--- a/OpenSim/Services/GridService/GridService.cs
+++ b/OpenSim/Services/GridService/GridService.cs
@@ -96,7 +96,7 @@ namespace OpenSim.Services.GridService
96 // has an identically named command 96 // has an identically named command
97 // 97 //
98 // XXX: We're relying on the OpenSimulator version being registered first, which is not well defined. 98 // XXX: We're relying on the OpenSimulator version being registered first, which is not well defined.
99 if (MainConsole.Instance.Commands.Resolve(new string[] { "show", "regions" }).Length == 0) 99 if (!MainConsole.Instance.Commands.HasCommand("show regions"))
100 MainConsole.Instance.Commands.AddCommand("Regions", true, 100 MainConsole.Instance.Commands.AddCommand("Regions", true,
101 "show regions", 101 "show regions",
102 "show regions", 102 "show regions",