diff options
author | Justin Clark-Casey (justincc) | 2012-03-08 01:51:37 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-03-08 01:51:37 +0000 |
commit | 749c3fef8ad2d3af97fcd9ab9c72740675e46715 (patch) | |
tree | 068e6adc89dc50386413d85064e80e3114e3fd49 /OpenSim/Framework/Console | |
parent | minor: make NPC tests run in a given order, comment out log lines in mock reg... (diff) | |
download | opensim-SC_OLD-749c3fef8ad2d3af97fcd9ab9c72740675e46715.zip opensim-SC_OLD-749c3fef8ad2d3af97fcd9ab9c72740675e46715.tar.gz opensim-SC_OLD-749c3fef8ad2d3af97fcd9ab9c72740675e46715.tar.bz2 opensim-SC_OLD-749c3fef8ad2d3af97fcd9ab9c72740675e46715.tar.xz |
Change "help" to display categories/module list then "help <category/module>" to display commands in a category.
This is to deal with the hundred lines of command splurge when one previously typed "help"
Modelled somewhat on the mysql console
One can still type help <command> to get per command help at any point.
Categories capitalized to avoid conflict with the all-lowercase commands (except for commander system, as of yet).
Does not affect command parsing or any other aspects of the console apart from the help system.
Backwards compatible with existing modules.
Diffstat (limited to 'OpenSim/Framework/Console')
-rw-r--r-- | OpenSim/Framework/Console/CommandConsole.cs | 114 |
1 files changed, 92 insertions, 22 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; | |||
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,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) |