aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Console')
-rw-r--r--OpenSim/Framework/Console/AssemblyInfo.cs4
-rw-r--r--OpenSim/Framework/Console/CommandConsole.cs31
-rwxr-xr-xOpenSim/Framework/Console/ConsoleBase.cs10
-rw-r--r--OpenSim/Framework/Console/ConsoleUtil.cs246
-rw-r--r--OpenSim/Framework/Console/MockConsole.cs7
5 files changed, 218 insertions, 80 deletions
diff --git a/OpenSim/Framework/Console/AssemblyInfo.cs b/OpenSim/Framework/Console/AssemblyInfo.cs
index 75e35bf..37c7304 100644
--- a/OpenSim/Framework/Console/AssemblyInfo.cs
+++ b/OpenSim/Framework/Console/AssemblyInfo.cs
@@ -39,7 +39,7 @@ using System.Runtime.InteropServices;
39[assembly: AssemblyConfiguration("")] 39[assembly: AssemblyConfiguration("")]
40[assembly: AssemblyCompany("http://opensimulator.org")] 40[assembly: AssemblyCompany("http://opensimulator.org")]
41[assembly : AssemblyProduct("ServerConsole")] 41[assembly : AssemblyProduct("ServerConsole")]
42[assembly: AssemblyCopyright("Copyright (c) OpenSimulator.org Developers 2007-2009")] 42[assembly: AssemblyCopyright("Copyright (c) OpenSimulator.org Developers")]
43[assembly: AssemblyTrademark("")] 43[assembly: AssemblyTrademark("")]
44[assembly: AssemblyCulture("")] 44[assembly: AssemblyCulture("")]
45 45
@@ -55,4 +55,4 @@ using System.Runtime.InteropServices;
55// You can specify all values by your own or you can build default build and revision 55// You can specify all values by your own or you can build default build and revision
56// numbers with the '*' character (the default): 56// numbers with the '*' character (the default):
57 57
58[assembly : AssemblyVersion("0.6.5.*")] 58[assembly : AssemblyVersion("0.7.5.*")]
diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs
index bd23d1c..de30414 100644
--- a/OpenSim/Framework/Console/CommandConsole.cs
+++ b/OpenSim/Framework/Console/CommandConsole.cs
@@ -83,7 +83,8 @@ namespace OpenSim.Framework.Console
83 = "To enter an argument that contains spaces, surround the argument with double quotes.\nFor example, show object name \"My long object name\"\n"; 83 = "To enter an argument that contains spaces, surround the argument with double quotes.\nFor example, show object name \"My long object name\"\n";
84 84
85 public const string ItemHelpText 85 public const string ItemHelpText
86 = "For more information, type 'help <item>' where <item> is one of the following:"; 86= @"For more information, type 'help all' to get a list of all commands,
87 or type help <item>' where <item> is one of the following:";
87 88
88 /// <value> 89 /// <value>
89 /// Commands organized by keyword in a tree 90 /// Commands organized by keyword in a tree
@@ -117,6 +118,10 @@ namespace OpenSim.Framework.Console
117 help.Add(ItemHelpText); 118 help.Add(ItemHelpText);
118 help.AddRange(CollectModulesHelp(tree)); 119 help.AddRange(CollectModulesHelp(tree));
119 } 120 }
121 else if (helpParts.Count == 1 && helpParts[0] == "all")
122 {
123 help.AddRange(CollectAllCommandsHelp());
124 }
120 else 125 else
121 { 126 {
122 help.AddRange(CollectHelp(helpParts)); 127 help.AddRange(CollectHelp(helpParts));
@@ -124,6 +129,28 @@ namespace OpenSim.Framework.Console
124 129
125 return help; 130 return help;
126 } 131 }
132
133 /// <summary>
134 /// Collects the help from all commands and return in alphabetical order.
135 /// </summary>
136 /// <returns></returns>
137 private List<string> CollectAllCommandsHelp()
138 {
139 List<string> help = new List<string>();
140
141 lock (m_modulesCommands)
142 {
143 foreach (List<CommandInfo> commands in m_modulesCommands.Values)
144 {
145 var ourHelpText = commands.ConvertAll(c => string.Format("{0} - {1}", c.help_text, c.long_help));
146 help.AddRange(ourHelpText);
147 }
148 }
149
150 help.Sort();
151
152 return help;
153 }
127 154
128 /// <summary> 155 /// <summary>
129 /// See if we can find the requested command in order to display longer help 156 /// See if we can find the requested command in order to display longer help
@@ -711,7 +738,7 @@ namespace OpenSim.Framework.Console
711 /// </summary> 738 /// </summary>
712 public void Prompt() 739 public void Prompt()
713 { 740 {
714 string line = ReadLine(m_defaultPrompt + "# ", true, true); 741 string line = ReadLine(DefaultPrompt + "# ", true, true);
715 742
716 if (line != String.Empty) 743 if (line != String.Empty)
717 Output("Invalid command"); 744 Output("Invalid command");
diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs
index 4b375d9..2d8e723 100755
--- a/OpenSim/Framework/Console/ConsoleBase.cs
+++ b/OpenSim/Framework/Console/ConsoleBase.cs
@@ -43,15 +43,7 @@ namespace OpenSim.Framework.Console
43 43
44 public object ConsoleScene { get; set; } 44 public object ConsoleScene { get; set; }
45 45
46 /// <summary> 46 public string DefaultPrompt { get; set; }
47 /// The default prompt text.
48 /// </summary>
49 public string DefaultPrompt
50 {
51 set { m_defaultPrompt = value; }
52 get { return m_defaultPrompt; }
53 }
54 protected string m_defaultPrompt;
55 47
56 public ConsoleBase(string defaultPrompt) 48 public ConsoleBase(string defaultPrompt)
57 { 49 {
diff --git a/OpenSim/Framework/Console/ConsoleUtil.cs b/OpenSim/Framework/Console/ConsoleUtil.cs
index a7cf0c0..16a63e0 100644
--- a/OpenSim/Framework/Console/ConsoleUtil.cs
+++ b/OpenSim/Framework/Console/ConsoleUtil.cs
@@ -27,88 +27,202 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO;
30using System.Linq; 31using System.Linq;
31using System.Reflection; 32using System.Reflection;
32using log4net; 33using log4net;
33using OpenMetaverse; 34using OpenMetaverse;
34 35
35public class ConsoleUtil 36namespace OpenSim.Framework.Console
36{ 37{
37// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 38 public class ConsoleUtil
38
39 public const string MinRawConsoleVectorValue = "-~";
40 public const string MaxRawConsoleVectorValue = "~";
41
42 public const string VectorSeparator = ",";
43 public static char[] VectorSeparatorChars = VectorSeparator.ToCharArray();
44
45 /// <summary>
46 /// Convert a minimum vector input from the console to an OpenMetaverse.Vector3
47 /// </summary>
48 /// <param name='rawConsoleVector'>/param>
49 /// <param name='vector'></param>
50 /// <returns></returns>
51 public static bool TryParseConsoleMinVector(string rawConsoleVector, out Vector3 vector)
52 { 39 {
53 return TryParseConsoleVector(rawConsoleVector, c => float.MinValue.ToString(), out vector); 40 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54 }
55 41
56 /// <summary> 42 public const int LocalIdNotFound = 0;
57 /// Convert a maximum vector input from the console to an OpenMetaverse.Vector3 43
58 /// </summary> 44 /// <summary>
59 /// <param name='rawConsoleVector'>/param> 45 /// Used by modules to display stock co-ordinate help, though possibly this should be under some general section
60 /// <param name='vector'></param> 46 /// rather than in each help summary.
61 /// <returns></returns> 47 /// </summary>
62 public static bool TryParseConsoleMaxVector(string rawConsoleVector, out Vector3 vector) 48 public const string CoordHelp
63 { 49 = @"Each component of the coord is comma separated. There must be no spaces between the commas.
64 return TryParseConsoleVector(rawConsoleVector, c => float.MaxValue.ToString(), out vector); 50 If you don't care about the z component you can simply omit it.
65 } 51 If you don't care about the x or y components then you can leave them blank (though a comma is still required)
52 If you want to specify the maxmimum value of a component then you can use ~ instead of a number
53 If you want to specify the minimum value of a component then you can use -~ instead of a number
54 e.g.
55 delete object pos 20,20,20 to 40,40,40
56 delete object pos 20,20 to 40,40
57 delete object pos ,20,20 to ,40,40
58 delete object pos ,,30 to ,,~
59 delete object pos ,,-~ to ,,30";
60
61 public const string MinRawConsoleVectorValue = "-~";
62 public const string MaxRawConsoleVectorValue = "~";
63
64 public const string VectorSeparator = ",";
65 public static char[] VectorSeparatorChars = VectorSeparator.ToCharArray();
66 66
67 /// <summary> 67 /// <summary>
68 /// Convert a vector input from the console to an OpenMetaverse.Vector3 68 /// Check if the given file path exists.
69 /// </summary> 69 /// </summary>
70 /// <param name='rawConsoleVector'> 70 /// <remarks>If not, warning is printed to the given console.</remarks>
71 /// A string in the form <x>,<y>,<z> where there is no space between values. 71 /// <returns>true if the file does not exist, false otherwise.</returns>
72 /// Any component can be missing (e.g. ,,40). blankComponentFunc is invoked to replace the blank with a suitable value 72 /// <param name='console'></param>
73 /// Also, if the blank component is at the end, then the comma can be missed off entirely (e.g. 40,30 or 40) 73 /// <param name='path'></param>
74 /// The strings "~" and "-~" are valid in components. The first substitutes float.MaxValue whilst the second is float.MinValue 74 public static bool CheckFileDoesNotExist(ICommandConsole console, string path)
75 /// Other than that, component values must be numeric. 75 {
76 /// </param> 76 if (File.Exists(path))
77 /// <param name='blankComponentFunc'></param> 77 {
78 /// <param name='vector'></param> 78 console.OutputFormat("File {0} already exists. Please move or remove it.", path);
79 /// <returns></returns> 79 return false;
80 public static bool TryParseConsoleVector( 80 }
81 string rawConsoleVector, Func<string, string> blankComponentFunc, out Vector3 vector)
82 {
83 List<string> components = rawConsoleVector.Split(VectorSeparatorChars).ToList();
84 81
85 if (components.Count < 1 || components.Count > 3) 82 return true;
83 }
84
85 /// <summary>
86 /// Try to parse a console UUID from the console.
87 /// </summary>
88 /// <remarks>
89 /// Will complain to the console if parsing fails.
90 /// </remarks>
91 /// <returns></returns>
92 /// <param name='console'>If null then no complaint is printed.</param>
93 /// <param name='rawUuid'></param>
94 /// <param name='uuid'></param>
95 public static bool TryParseConsoleUuid(ICommandConsole console, string rawUuid, out UUID uuid)
86 { 96 {
87 vector = Vector3.Zero; 97 if (!UUID.TryParse(rawUuid, out uuid))
88 return false; 98 {
99 if (console != null)
100 console.OutputFormat("{0} is not a valid uuid", rawUuid);
101
102 return false;
103 }
104
105 return true;
89 } 106 }
90 107
91 for (int i = components.Count; i < 3; i++) 108 public static bool TryParseConsoleLocalId(ICommandConsole console, string rawLocalId, out uint localId)
92 components.Add(""); 109 {
110 if (!uint.TryParse(rawLocalId, out localId))
111 {
112 if (console != null)
113 console.OutputFormat("{0} is not a valid local id", localId);
114
115 return false;
116 }
93 117
94 List<string> semiDigestedComponents 118 if (localId == 0)
95 = components.ConvertAll<string>( 119 {
96 c => 120 if (console != null)
97 { 121 console.OutputFormat("{0} is not a valid local id - it must be greater than 0", localId);
98 if (c == "")
99 return blankComponentFunc.Invoke(c);
100 else if (c == MaxRawConsoleVectorValue)
101 return float.MaxValue.ToString();
102 else if (c == MinRawConsoleVectorValue)
103 return float.MinValue.ToString();
104 else
105 return c;
106 });
107 122
108 string semiDigestedConsoleVector = string.Join(VectorSeparator, semiDigestedComponents.ToArray()); 123 return false;
124 }
109 125
110// m_log.DebugFormat("[CONSOLE UTIL]: Parsing {0} into OpenMetaverse.Vector3", semiDigestedConsoleVector); 126 return true;
127 }
128
129 /// <summary>
130 /// Tries to parse the input as either a UUID or a local ID.
131 /// </summary>
132 /// <returns>true if parsing succeeded, false otherwise.</returns>
133 /// <param name='console'></param>
134 /// <param name='rawId'></param>
135 /// <param name='uuid'></param>
136 /// <param name='localId'>
137 /// Will be set to ConsoleUtil.LocalIdNotFound if parsing result was a UUID or no parse succeeded.
138 /// </param>
139 public static bool TryParseConsoleId(ICommandConsole console, string rawId, out UUID uuid, out uint localId)
140 {
141 if (TryParseConsoleUuid(null, rawId, out uuid))
142 {
143 localId = LocalIdNotFound;
144 return true;
145 }
146
147 if (TryParseConsoleLocalId(null, rawId, out localId))
148 {
149 return true;
150 }
111 151
112 return Vector3.TryParse(semiDigestedConsoleVector, out vector); 152 if (console != null)
153 console.OutputFormat("{0} is not a valid UUID or local id", rawId);
154
155 return false;
156 }
157
158 /// <summary>
159 /// Convert a minimum vector input from the console to an OpenMetaverse.Vector3
160 /// </summary>
161 /// <param name='rawConsoleVector'>/param>
162 /// <param name='vector'></param>
163 /// <returns></returns>
164 public static bool TryParseConsoleMinVector(string rawConsoleVector, out Vector3 vector)
165 {
166 return TryParseConsoleVector(rawConsoleVector, c => float.MinValue.ToString(), out vector);
167 }
168
169 /// <summary>
170 /// Convert a maximum vector input from the console to an OpenMetaverse.Vector3
171 /// </summary>
172 /// <param name='rawConsoleVector'>/param>
173 /// <param name='vector'></param>
174 /// <returns></returns>
175 public static bool TryParseConsoleMaxVector(string rawConsoleVector, out Vector3 vector)
176 {
177 return TryParseConsoleVector(rawConsoleVector, c => float.MaxValue.ToString(), out vector);
178 }
179
180 /// <summary>
181 /// Convert a vector input from the console to an OpenMetaverse.Vector3
182 /// </summary>
183 /// <param name='rawConsoleVector'>
184 /// A string in the form <x>,<y>,<z> where there is no space between values.
185 /// Any component can be missing (e.g. ,,40). blankComponentFunc is invoked to replace the blank with a suitable value
186 /// Also, if the blank component is at the end, then the comma can be missed off entirely (e.g. 40,30 or 40)
187 /// The strings "~" and "-~" are valid in components. The first substitutes float.MaxValue whilst the second is float.MinValue
188 /// Other than that, component values must be numeric.
189 /// </param>
190 /// <param name='blankComponentFunc'></param>
191 /// <param name='vector'></param>
192 /// <returns></returns>
193 public static bool TryParseConsoleVector(
194 string rawConsoleVector, Func<string, string> blankComponentFunc, out Vector3 vector)
195 {
196 List<string> components = rawConsoleVector.Split(VectorSeparatorChars).ToList();
197
198 if (components.Count < 1 || components.Count > 3)
199 {
200 vector = Vector3.Zero;
201 return false;
202 }
203
204 for (int i = components.Count; i < 3; i++)
205 components.Add("");
206
207 List<string> semiDigestedComponents
208 = components.ConvertAll<string>(
209 c =>
210 {
211 if (c == "")
212 return blankComponentFunc.Invoke(c);
213 else if (c == MaxRawConsoleVectorValue)
214 return float.MaxValue.ToString();
215 else if (c == MinRawConsoleVectorValue)
216 return float.MinValue.ToString();
217 else
218 return c;
219 });
220
221 string semiDigestedConsoleVector = string.Join(VectorSeparator, semiDigestedComponents.ToArray());
222
223 // m_log.DebugFormat("[CONSOLE UTIL]: Parsing {0} into OpenMetaverse.Vector3", semiDigestedConsoleVector);
224
225 return Vector3.TryParse(semiDigestedConsoleVector, out vector);
226 }
113 } 227 }
114} \ No newline at end of file 228} \ No newline at end of file
diff --git a/OpenSim/Framework/Console/MockConsole.cs b/OpenSim/Framework/Console/MockConsole.cs
index b489f93..8ba58e4 100644
--- a/OpenSim/Framework/Console/MockConsole.cs
+++ b/OpenSim/Framework/Console/MockConsole.cs
@@ -46,13 +46,18 @@ namespace OpenSim.Framework.Console
46 46
47 public ICommands Commands { get { return m_commands; } } 47 public ICommands Commands { get { return m_commands; } }
48 48
49 public string DefaultPrompt { get; set; }
50
49 public void Prompt() {} 51 public void Prompt() {}
50 52
51 public void RunCommand(string cmd) {} 53 public void RunCommand(string cmd) {}
52 54
53 public string ReadLine(string p, bool isCommand, bool e) { return ""; } 55 public string ReadLine(string p, bool isCommand, bool e) { return ""; }
54 56
55 public object ConsoleScene { get { return null; } } 57 public object ConsoleScene {
58 get { return null; }
59 set {}
60 }
56 61
57 public void Output(string text, string level) {} 62 public void Output(string text, string level) {}
58 public void Output(string text) {} 63 public void Output(string text) {}