aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console
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 /OpenSim/Framework/Console
parentrefactor: slightly adjust some code in ODECharacter.Move() to eliminate a con... (diff)
downloadopensim-SC_OLD-9be935ac6d74fd3b8c0c95058a575e400dd916a4.zip
opensim-SC_OLD-9be935ac6d74fd3b8c0c95058a575e400dd916a4.tar.gz
opensim-SC_OLD-9be935ac6d74fd3b8c0c95058a575e400dd916a4.tar.bz2
opensim-SC_OLD-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
Diffstat (limited to 'OpenSim/Framework/Console')
-rw-r--r--OpenSim/Framework/Console/CommandConsole.cs46
-rw-r--r--OpenSim/Framework/Console/MockConsole.cs1
2 files changed, 32 insertions, 15 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 }