diff options
Diffstat (limited to 'OpenSim/Framework/Console/CommandConsole.cs')
-rw-r--r-- | OpenSim/Framework/Console/CommandConsole.cs | 122 |
1 files changed, 97 insertions, 25 deletions
diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs index 0d6288b..c5d6b78 100644 --- a/OpenSim/Framework/Console/CommandConsole.cs +++ b/OpenSim/Framework/Console/CommandConsole.cs | |||
@@ -29,6 +29,7 @@ using System; | |||
29 | using System.Xml; | 29 | using System.Xml; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Diagnostics; | 31 | using System.Diagnostics; |
32 | using System.Linq; | ||
32 | using System.Reflection; | 33 | using System.Reflection; |
33 | using System.Text; | 34 | using System.Text; |
34 | using System.Text.RegularExpressions; | 35 | using 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,63 @@ 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 | foreach (string key in m_modulesCommands.Keys) |
171 | { | 192 | { |
172 | result.AddRange(CollectHelp((Dictionary<string, Object>)kvp.Value)); | 193 | // Allow topic help requests to succeed whether they are upper or lowercase. |
173 | } | 194 | if (moduleName.ToLower() == key.ToLower()) |
174 | else | 195 | { |
175 | { | 196 | List<CommandInfo> commands = m_modulesCommands[key]; |
176 | if (((CommandInfo)kvp.Value).long_help != String.Empty) | 197 | var ourHelpText = commands.ConvertAll(c => string.Format("{0} - {1}", c.help_text, c.long_help)); |
177 | result.Add(((CommandInfo)kvp.Value).help_text+" - "+ | 198 | ourHelpText.Sort(); |
178 | ((CommandInfo)kvp.Value).long_help); | 199 | helpText.AddRange(ourHelpText); |
200 | |||
201 | return true; | ||
202 | } | ||
179 | } | 203 | } |
204 | |||
205 | return false; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | private List<string> CollectModulesHelp(Dictionary<string, object> dict) | ||
210 | { | ||
211 | lock (m_modulesCommands) | ||
212 | { | ||
213 | List<string> helpText = new List<string>(m_modulesCommands.Keys); | ||
214 | helpText.Sort(); | ||
215 | return helpText; | ||
180 | } | 216 | } |
181 | return result; | ||
182 | } | 217 | } |
218 | |||
219 | // private List<string> CollectHelp(Dictionary<string, object> dict) | ||
220 | // { | ||
221 | // List<string> result = new List<string>(); | ||
222 | // | ||
223 | // foreach (KeyValuePair<string, object> kvp in dict) | ||
224 | // { | ||
225 | // if (kvp.Value is Dictionary<string, Object>) | ||
226 | // { | ||
227 | // result.AddRange(CollectHelp((Dictionary<string, Object>)kvp.Value)); | ||
228 | // } | ||
229 | // else | ||
230 | // { | ||
231 | // if (((CommandInfo)kvp.Value).long_help != String.Empty) | ||
232 | // result.Add(((CommandInfo)kvp.Value).help_text+" - "+ | ||
233 | // ((CommandInfo)kvp.Value).long_help); | ||
234 | // } | ||
235 | // } | ||
236 | // return result; | ||
237 | // } | ||
183 | 238 | ||
184 | /// <summary> | 239 | /// <summary> |
185 | /// Add a command to those which can be invoked from the console. | 240 | /// Add a command to those which can be invoked from the console. |
@@ -212,21 +267,19 @@ namespace OpenSim.Framework.Console | |||
212 | 267 | ||
213 | Dictionary<string, Object> current = tree; | 268 | Dictionary<string, Object> current = tree; |
214 | 269 | ||
215 | foreach (string s in parts) | 270 | foreach (string part in parts) |
216 | { | 271 | { |
217 | if (current.ContainsKey(s)) | 272 | if (current.ContainsKey(part)) |
218 | { | 273 | { |
219 | if (current[s] is Dictionary<string, Object>) | 274 | if (current[part] is Dictionary<string, Object>) |
220 | { | 275 | current = (Dictionary<string, Object>)current[part]; |
221 | current = (Dictionary<string, Object>)current[s]; | ||
222 | } | ||
223 | else | 276 | else |
224 | return; | 277 | return; |
225 | } | 278 | } |
226 | else | 279 | else |
227 | { | 280 | { |
228 | current[s] = new Dictionary<string, Object>(); | 281 | current[part] = new Dictionary<string, Object>(); |
229 | current = (Dictionary<string, Object>)current[s]; | 282 | current = (Dictionary<string, Object>)current[part]; |
230 | } | 283 | } |
231 | } | 284 | } |
232 | 285 | ||
@@ -250,6 +303,24 @@ namespace OpenSim.Framework.Console | |||
250 | info.fn = new List<CommandDelegate>(); | 303 | info.fn = new List<CommandDelegate>(); |
251 | info.fn.Add(fn); | 304 | info.fn.Add(fn); |
252 | current[String.Empty] = info; | 305 | current[String.Empty] = info; |
306 | |||
307 | // Now add command to modules dictionary | ||
308 | lock (m_modulesCommands) | ||
309 | { | ||
310 | List<CommandInfo> commands; | ||
311 | if (m_modulesCommands.ContainsKey(module)) | ||
312 | { | ||
313 | commands = m_modulesCommands[module]; | ||
314 | } | ||
315 | else | ||
316 | { | ||
317 | commands = new List<CommandInfo>(); | ||
318 | m_modulesCommands[module] = commands; | ||
319 | } | ||
320 | |||
321 | // m_log.DebugFormat("[COMMAND CONSOLE]: Adding to category {0} command {1}", module, command); | ||
322 | commands.Add(info); | ||
323 | } | ||
253 | } | 324 | } |
254 | 325 | ||
255 | public string[] FindNextOption(string[] cmd, bool term) | 326 | public string[] FindNextOption(string[] cmd, bool term) |
@@ -607,8 +678,9 @@ namespace OpenSim.Framework.Console | |||
607 | { | 678 | { |
608 | Commands = new Commands(); | 679 | Commands = new Commands(); |
609 | 680 | ||
610 | Commands.AddCommand("console", false, "help", "help [<command>]", | 681 | Commands.AddCommand( |
611 | "Get general command list or more detailed help on a specific command", Help); | 682 | "Help", false, "help", "help [<item>]", |
683 | "Display help on a particular command or on a list of commands in a category", Help); | ||
612 | } | 684 | } |
613 | 685 | ||
614 | private void Help(string module, string[] cmd) | 686 | private void Help(string module, string[] cmd) |