aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Console/CommandConsole.cs114
-rw-r--r--OpenSim/Framework/ICommandConsole.cs2
-rw-r--r--OpenSim/Framework/Servers/BaseOpenSimServer.cs20
3 files changed, 103 insertions, 33 deletions
diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs
index 0d6288b..2bb7de1 100644
--- a/OpenSim/Framework/Console/CommandConsole.cs
+++ b/OpenSim/Framework/Console/CommandConsole.cs
@@ -29,6 +29,7 @@ using System;
29using System.Xml; 29using System.Xml;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Diagnostics; 31using System.Diagnostics;
32using System.Linq;
32using System.Reflection; 33using System.Reflection;
33using System.Text; 34using System.Text;
34using System.Text.RegularExpressions; 35using System.Text.RegularExpressions;
@@ -40,6 +41,8 @@ namespace OpenSim.Framework.Console
40{ 41{
41 public class Commands : ICommands 42 public class Commands : ICommands
42 { 43 {
44// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45
43 /// <summary> 46 /// <summary>
44 /// Encapsulates a command that can be invoked from the console 47 /// Encapsulates a command that can be invoked from the console
45 /// </summary> 48 /// </summary>
@@ -76,6 +79,8 @@ namespace OpenSim.Framework.Console
76 public List<CommandDelegate> fn; 79 public List<CommandDelegate> fn;
77 } 80 }
78 81
82 public const string GeneralHelpText = "For more information, type 'help <item>' where <item> is one of the following categories:";
83
79 /// <value> 84 /// <value>
80 /// Commands organized by keyword in a tree 85 /// Commands organized by keyword in a tree
81 /// </value> 86 /// </value>
@@ -83,6 +88,11 @@ namespace OpenSim.Framework.Console
83 new Dictionary<string, object>(); 88 new Dictionary<string, object>();
84 89
85 /// <summary> 90 /// <summary>
91 /// Commands organized by module
92 /// </summary>
93 private Dictionary<string, List<CommandInfo>> m_modulesCommands = new Dictionary<string, List<CommandInfo>>();
94
95 /// <summary>
86 /// Get help for the given help string 96 /// Get help for the given help string
87 /// </summary> 97 /// </summary>
88 /// <param name="helpParts">Parsed parts of the help string. If empty then general help is returned.</param> 98 /// <param name="helpParts">Parsed parts of the help string. If empty then general help is returned.</param>
@@ -98,8 +108,8 @@ namespace OpenSim.Framework.Console
98 // General help 108 // General help
99 if (helpParts.Count == 0) 109 if (helpParts.Count == 0)
100 { 110 {
101 help.AddRange(CollectHelp(tree)); 111 help.Add(GeneralHelpText);
102 help.Sort(); 112 help.AddRange(CollectModulesHelp(tree));
103 } 113 }
104 else 114 else
105 { 115 {
@@ -118,6 +128,13 @@ namespace OpenSim.Framework.Console
118 { 128 {
119 string originalHelpRequest = string.Join(" ", helpParts.ToArray()); 129 string originalHelpRequest = string.Join(" ", helpParts.ToArray());
120 List<string> help = new List<string>(); 130 List<string> help = new List<string>();
131
132 // Check modules first to see if we just need to display a list of those commands
133 if (TryCollectModuleHelp(originalHelpRequest, help))
134 {
135 help.Insert(0, GeneralHelpText);
136 return help;
137 }
121 138
122 Dictionary<string, object> dict = tree; 139 Dictionary<string, object> dict = tree;
123 while (helpParts.Count > 0) 140 while (helpParts.Count > 0)
@@ -161,25 +178,61 @@ namespace OpenSim.Framework.Console
161 return help; 178 return help;
162 } 179 }
163 180
164 private List<string> CollectHelp(Dictionary<string, object> dict) 181 /// <summary>
182 /// Try to collect help for the given module if that module exists.
183 /// </summary>
184 /// <param name="moduleName"></param>
185 /// <param name="helpText">/param>
186 /// <returns>true if there was the module existed, false otherwise.</returns>
187 private bool TryCollectModuleHelp(string moduleName, List<string> helpText)
165 { 188 {
166 List<string> result = new List<string>(); 189 lock (m_modulesCommands)
167
168 foreach (KeyValuePair<string, object> kvp in dict)
169 { 190 {
170 if (kvp.Value is Dictionary<string, Object>) 191 if (m_modulesCommands.ContainsKey(moduleName))
171 { 192 {
172 result.AddRange(CollectHelp((Dictionary<string, Object>)kvp.Value)); 193 List<CommandInfo> commands = m_modulesCommands[moduleName];
194 var ourHelpText = commands.ConvertAll(c => string.Format("{0} - {1}", c.help_text, c.long_help));
195 ourHelpText.Sort();
196 helpText.AddRange(ourHelpText);
197
198 return true;
173 } 199 }
174 else 200 else
175 { 201 {
176 if (((CommandInfo)kvp.Value).long_help != String.Empty) 202 return false;
177 result.Add(((CommandInfo)kvp.Value).help_text+" - "+
178 ((CommandInfo)kvp.Value).long_help);
179 } 203 }
180 } 204 }
181 return result;
182 } 205 }
206
207 private List<string> CollectModulesHelp(Dictionary<string, object> dict)
208 {
209 lock (m_modulesCommands)
210 {
211 List<string> helpText = new List<string>(m_modulesCommands.Keys);
212 helpText.Sort();
213 return helpText;
214 }
215 }
216
217// private List<string> CollectHelp(Dictionary<string, object> dict)
218// {
219// List<string> result = new List<string>();
220//
221// foreach (KeyValuePair<string, object> kvp in dict)
222// {
223// if (kvp.Value is Dictionary<string, Object>)
224// {
225// result.AddRange(CollectHelp((Dictionary<string, Object>)kvp.Value));
226// }
227// else
228// {
229// if (((CommandInfo)kvp.Value).long_help != String.Empty)
230// result.Add(((CommandInfo)kvp.Value).help_text+" - "+
231// ((CommandInfo)kvp.Value).long_help);
232// }
233// }
234// return result;
235// }
183 236
184 /// <summary> 237 /// <summary>
185 /// Add a command to those which can be invoked from the console. 238 /// Add a command to those which can be invoked from the console.
@@ -212,21 +265,19 @@ namespace OpenSim.Framework.Console
212 265
213 Dictionary<string, Object> current = tree; 266 Dictionary<string, Object> current = tree;
214 267
215 foreach (string s in parts) 268 foreach (string part in parts)
216 { 269 {
217 if (current.ContainsKey(s)) 270 if (current.ContainsKey(part))
218 { 271 {
219 if (current[s] is Dictionary<string, Object>) 272 if (current[part] is Dictionary<string, Object>)
220 { 273 current = (Dictionary<string, Object>)current[part];
221 current = (Dictionary<string, Object>)current[s];
222 }
223 else 274 else
224 return; 275 return;
225 } 276 }
226 else 277 else
227 { 278 {
228 current[s] = new Dictionary<string, Object>(); 279 current[part] = new Dictionary<string, Object>();
229 current = (Dictionary<string, Object>)current[s]; 280 current = (Dictionary<string, Object>)current[part];
230 } 281 }
231 } 282 }
232 283
@@ -250,6 +301,24 @@ namespace OpenSim.Framework.Console
250 info.fn = new List<CommandDelegate>(); 301 info.fn = new List<CommandDelegate>();
251 info.fn.Add(fn); 302 info.fn.Add(fn);
252 current[String.Empty] = info; 303 current[String.Empty] = info;
304
305 // Now add command to modules dictionary
306 lock (m_modulesCommands)
307 {
308 List<CommandInfo> commands;
309 if (m_modulesCommands.ContainsKey(module))
310 {
311 commands = m_modulesCommands[module];
312 }
313 else
314 {
315 commands = new List<CommandInfo>();
316 m_modulesCommands[module] = commands;
317 }
318
319// m_log.DebugFormat("[COMMAND CONSOLE]: Adding to category {0} command {1}", module, command);
320 commands.Add(info);
321 }
253 } 322 }
254 323
255 public string[] FindNextOption(string[] cmd, bool term) 324 public string[] FindNextOption(string[] cmd, bool term)
@@ -607,8 +676,9 @@ namespace OpenSim.Framework.Console
607 { 676 {
608 Commands = new Commands(); 677 Commands = new Commands();
609 678
610 Commands.AddCommand("console", false, "help", "help [<command>]", 679 Commands.AddCommand(
611 "Get general command list or more detailed help on a specific command", Help); 680 "Help", false, "help", "help [<item>]",
681 "Display help on a particular command or on a list of commands in a category", Help);
612 } 682 }
613 683
614 private void Help(string module, string[] cmd) 684 private void Help(string module, string[] cmd)
diff --git a/OpenSim/Framework/ICommandConsole.cs b/OpenSim/Framework/ICommandConsole.cs
index d33b9b5..ca0ff93 100644
--- a/OpenSim/Framework/ICommandConsole.cs
+++ b/OpenSim/Framework/ICommandConsole.cs
@@ -40,7 +40,7 @@ namespace OpenSim.Framework
40 /// <summary> 40 /// <summary>
41 /// Get help for the given help string 41 /// Get help for the given help string
42 /// </summary> 42 /// </summary>
43 /// <param name="helpParts">Parsed parts of the help string. If empty then general help is returned.</param> 43 /// <param name="cmd">Parsed parts of the help string. If empty then general help is returned.</param>
44 /// <returns></returns> 44 /// <returns></returns>
45 List<string> GetHelp(string[] cmd); 45 List<string> GetHelp(string[] cmd);
46 46
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index daddd1f..f4d541e 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -161,43 +161,43 @@ namespace OpenSim.Framework.Servers
161 Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold)); 161 Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
162 } 162 }
163 163
164 m_console.Commands.AddCommand("base", false, "quit", 164 m_console.Commands.AddCommand("General", false, "quit",
165 "quit", 165 "quit",
166 "Quit the application", HandleQuit); 166 "Quit the application", HandleQuit);
167 167
168 m_console.Commands.AddCommand("base", false, "shutdown", 168 m_console.Commands.AddCommand("General", false, "shutdown",
169 "shutdown", 169 "shutdown",
170 "Quit the application", HandleQuit); 170 "Quit the application", HandleQuit);
171 171
172 m_console.Commands.AddCommand("base", false, "set log level", 172 m_console.Commands.AddCommand("General", false, "set log level",
173 "set log level <level>", 173 "set log level <level>",
174 "Set the console logging level", HandleLogLevel); 174 "Set the console logging level", HandleLogLevel);
175 175
176 m_console.Commands.AddCommand("base", false, "show info", 176 m_console.Commands.AddCommand("General", false, "show info",
177 "show info", 177 "show info",
178 "Show general information about the server", HandleShow); 178 "Show general information about the server", HandleShow);
179 179
180 m_console.Commands.AddCommand("base", false, "show stats", 180 m_console.Commands.AddCommand("General", false, "show stats",
181 "show stats", 181 "show stats",
182 "Show statistics", HandleShow); 182 "Show statistics", HandleShow);
183 183
184 m_console.Commands.AddCommand("base", false, "show threads", 184 m_console.Commands.AddCommand("General", false, "show threads",
185 "show threads", 185 "show threads",
186 "Show thread status", HandleShow); 186 "Show thread status", HandleShow);
187 187
188 m_console.Commands.AddCommand("base", false, "show uptime", 188 m_console.Commands.AddCommand("General", false, "show uptime",
189 "show uptime", 189 "show uptime",
190 "Show server uptime", HandleShow); 190 "Show server uptime", HandleShow);
191 191
192 m_console.Commands.AddCommand("base", false, "show version", 192 m_console.Commands.AddCommand("General", false, "show version",
193 "show version", 193 "show version",
194 "Show server version", HandleShow); 194 "Show server version", HandleShow);
195 195
196 m_console.Commands.AddCommand("base", false, "threads abort", 196 m_console.Commands.AddCommand("General", false, "threads abort",
197 "threads abort <thread-id>", 197 "threads abort <thread-id>",
198 "Abort a managed thread. Use \"show threads\" to find possible threads.", HandleThreadsAbort); 198 "Abort a managed thread. Use \"show threads\" to find possible threads.", HandleThreadsAbort);
199 199
200 m_console.Commands.AddCommand("base", false, "threads show", 200 m_console.Commands.AddCommand("General", false, "threads show",
201 "threads show", 201 "threads show",
202 "Show thread status. Synonym for \"show threads\"", 202 "Show thread status. Synonym for \"show threads\"",
203 (string module, string[] args) => Notice(GetThreadsReport())); 203 (string module, string[] args) => Notice(GetThreadsReport()));