aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-02-09 20:52:04 +0000
committerJustin Clarke Casey2009-02-09 20:52:04 +0000
commita034b640dab9d08b23270e1ee8255ae92fa8f816 (patch)
treebe960c46df5062b5e9e2d1e17fe402ef0596fadd /OpenSim/Framework/Console
parenta last set of files that seem to have embedded ^M in them (diff)
downloadopensim-SC_OLD-a034b640dab9d08b23270e1ee8255ae92fa8f816.zip
opensim-SC_OLD-a034b640dab9d08b23270e1ee8255ae92fa8f816.tar.gz
opensim-SC_OLD-a034b640dab9d08b23270e1ee8255ae92fa8f816.tar.bz2
opensim-SC_OLD-a034b640dab9d08b23270e1ee8255ae92fa8f816.tar.xz
* Add the ability to type help <command> for more detailed help about a specific command if any is available
Diffstat (limited to 'OpenSim/Framework/Console')
-rw-r--r--OpenSim/Framework/Console/ConsoleBase.cs129
1 files changed, 121 insertions, 8 deletions
diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs
index 380894d..ef9b224 100644
--- a/OpenSim/Framework/Console/ConsoleBase.cs
+++ b/OpenSim/Framework/Console/ConsoleBase.cs
@@ -38,27 +38,111 @@ namespace OpenSim.Framework.Console
38 38
39 public class Commands 39 public class Commands
40 { 40 {
41 /// <summary>
42 /// Encapsulates a command that can be invoked from the console
43 /// </summary>
41 private class CommandInfo 44 private class CommandInfo
42 { 45 {
46 /// <value>
47 /// The module from which this command comes
48 /// </value>
43 public string module; 49 public string module;
50
51 /// <value>
52 /// Very short BNF description
53 /// </value>
44 public string help_text; 54 public string help_text;
55
56 /// <value>
57 /// Longer one line help text
58 /// </value>
45 public string long_help; 59 public string long_help;
60
61 /// <value>
62 /// Full descriptive help for this command
63 /// </value>
64 public string descriptive_help;
65
66 /// <value>
67 /// The method to invoke for this command
68 /// </value>
46 public CommandDelegate fn; 69 public CommandDelegate fn;
47 } 70 }
48 71
72 /// <value>
73 /// Commands organized by keyword in a tree
74 /// </value>
49 private Dictionary<string, Object> tree = 75 private Dictionary<string, Object> tree =
50 new Dictionary<string, Object>(); 76 new Dictionary<string, Object>();
51 77
52 public List<string> GetHelp() 78 /// <summary>
53 { 79 /// Get help for the given help string
80 /// </summary>
81 /// <param name="helpParts">Parsed parts of the help string. If empty then general help is returned.</param>
82 /// <returns></returns>
83 public List<string> GetHelp(string[] cmd)
84 {
54 List<string> help = new List<string>(); 85 List<string> help = new List<string>();
86 List<string> helpParts = new List<string>(cmd);
87
88 // Remove initial help keyword
89 helpParts.RemoveAt(0);
55 90
56 help.AddRange(CollectHelp(tree)); 91 // General help
57 92 if (helpParts.Count == 0)
58 help.Sort(); 93 {
94 help.AddRange(CollectHelp(tree));
95 help.Sort();
96 }
97 else
98 {
99 help.AddRange(CollectHelp(helpParts));
100 }
59 101
60 return help; 102 return help;
61 } 103 }
104
105 /// <summary>
106 /// See if we can find the requested command in order to display longer help
107 /// </summary>
108 /// <param name="helpParts"></param>
109 /// <returns></returns>
110 private List<string> CollectHelp(List<string> helpParts)
111 {
112 string originalHelpRequest = string.Join(" ", helpParts.ToArray());
113 List<string> help = new List<string>();
114
115 Dictionary<string, object> dict = tree;
116 while (helpParts.Count > 0)
117 {
118 string helpPart = helpParts[0];
119
120 if (!dict.ContainsKey(helpPart))
121 break;
122
123 //System.Console.WriteLine("Found {0}", helpParts[0]);
124
125 if (dict[helpPart] is Dictionary<string, Object>)
126 dict = (Dictionary<string, object>)dict[helpPart];
127
128 helpParts.RemoveAt(0);
129 }
130
131 // There was a command for the given help string
132 if (dict.ContainsKey(String.Empty))
133 {
134 CommandInfo commandInfo = (CommandInfo)dict[String.Empty];
135 help.Add(commandInfo.help_text);
136 help.Add(commandInfo.long_help);
137 help.Add(commandInfo.descriptive_help);
138 }
139 else
140 {
141 help.Add(string.Format("No help is available for {0}", originalHelpRequest));
142 }
143
144 return help;
145 }
62 146
63 private List<string> CollectHelp(Dictionary<string, Object> dict) 147 private List<string> CollectHelp(Dictionary<string, Object> dict)
64 { 148 {
@@ -79,12 +163,37 @@ namespace OpenSim.Framework.Console
79 } 163 }
80 return result; 164 return result;
81 } 165 }
166
167 /// <summary>
168 /// Add a command to those which can be invoked from the console.
169 /// </summary>
170 /// <param name="module"></param>
171 /// <param name="command"></param>
172 /// <param name="help"></param>
173 /// <param name="longhelp"></param>
174 /// <param name="fn"></param>
175 public void AddCommand(
176 string module, string command, string help, string longhelp, CommandDelegate fn)
177 {
178 AddCommand(module, command, help, longhelp, String.Empty, fn);
179 }
82 180
83 public void AddCommand(string module, string command, string help, string longhelp, CommandDelegate fn) 181 /// <summary>
182 /// Add a command to those which can be invoked from the console.
183 /// </summary>
184 /// <param name="module"></param>
185 /// <param name="command"></param>
186 /// <param name="help"></param>
187 /// <param name="longhelp"></param>
188 /// <param name="descriptivehelp"></param>
189 /// <param name="fn"></param>
190 public void AddCommand(
191 string module, string command, string help, string longhelp, string descriptivehelp, CommandDelegate fn)
84 { 192 {
85 string[] parts = Parser.Parse(command); 193 string[] parts = Parser.Parse(command);
86 194
87 Dictionary<string, Object> current = tree; 195 Dictionary<string, Object> current = tree;
196
88 foreach (string s in parts) 197 foreach (string s in parts)
89 { 198 {
90 if (current.ContainsKey(s)) 199 if (current.ContainsKey(s))
@@ -105,10 +214,12 @@ namespace OpenSim.Framework.Console
105 214
106 if (current.ContainsKey(String.Empty)) 215 if (current.ContainsKey(String.Empty))
107 return; 216 return;
217
108 CommandInfo info = new CommandInfo(); 218 CommandInfo info = new CommandInfo();
109 info.module = module; 219 info.module = module;
110 info.help_text = help; 220 info.help_text = help;
111 info.long_help = longhelp; 221 info.long_help = longhelp;
222 info.descriptive_help = descriptivehelp;
112 info.fn = fn; 223 info.fn = fn;
113 current[String.Empty] = info; 224 current[String.Empty] = info;
114 } 225 }
@@ -285,7 +396,9 @@ namespace OpenSim.Framework.Console
285 { 396 {
286 DefaultPrompt = defaultPrompt; 397 DefaultPrompt = defaultPrompt;
287 398
288 Commands.AddCommand("console", "help", "help", "Get command list", Help); 399 Commands.AddCommand(
400 "console", "help", "help [<command>]",
401 "Get general command list or more detailed help on a specific command", Help);
289 } 402 }
290 403
291 private void AddToHistory(string text) 404 private void AddToHistory(string text)
@@ -517,7 +630,7 @@ namespace OpenSim.Framework.Console
517 630
518 private void Help(string module, string[] cmd) 631 private void Help(string module, string[] cmd)
519 { 632 {
520 List<string> help = Commands.GetHelp(); 633 List<string> help = Commands.GetHelp(cmd);
521 634
522 foreach (string s in help) 635 foreach (string s in help)
523 Output(s); 636 Output(s);