29 using System.Collections.Generic;
30 using OpenSim.Region.Framework.Interfaces;
33 namespace OpenSim.Region.CoreModules.Framework.InterfaceCommander
42 private List<CommandArgument> m_args =
new List<CommandArgument>();
44 private Action<object[]> m_command;
45 private string m_help;
46 private string m_name;
54 m_intentions = intention;
57 #region ICommand Members
59 public void AddArgument(
string name,
string helptext,
string type)
66 get {
return m_name; }
71 get {
return m_intentions; }
76 get {
return m_help; }
79 public Dictionary<string, string> Arguments
83 Dictionary<string, string> tmp =
new Dictionary<string, string>();
86 tmp.Add(arg.Name, arg.ArgumentType);
98 help +=
" <" + arg.Name +
">";
106 Console.WriteLine(
"== " + Name +
" ==");
107 Console.WriteLine(m_help);
108 Console.WriteLine(
"= Parameters =");
111 Console.WriteLine(
"* " + arg.Name +
" (" + arg.ArgumentType +
")");
112 Console.WriteLine(
"\t" + arg.HelpText);
116 public void Run(Object[] args)
120 if (args.Length < cleanArgs.Length)
122 Console.WriteLine(
"ERROR: Missing " + (cleanArgs.Length - args.Length) +
" argument(s)");
126 if (args.Length > cleanArgs.Length)
128 Console.WriteLine(
"ERROR: Too many arguments for this command. Type '<module> <command> help' for help.");
133 foreach (
Object arg
in args)
135 if (
string.IsNullOrEmpty(arg.ToString()))
137 Console.WriteLine(
"ERROR: Empty arguments are not allowed");
142 switch (m_args[i].ArgumentType)
145 m_args[i].ArgumentValue = arg.ToString();
148 m_args[i].ArgumentValue = Int32.Parse(arg.ToString());
151 m_args[i].ArgumentValue = Double.Parse(arg.ToString(),
OpenSim.Framework.Culture.NumberFormatInfo);
154 m_args[i].ArgumentValue = Boolean.Parse(arg.ToString());
157 m_args[i].ArgumentValue = UUID.Parse(arg.ToString());
160 Console.WriteLine(
"ERROR: Unknown desired type for argument " + m_args[i].Name +
" on command " + m_name);
164 catch (FormatException)
166 Console.WriteLine(
"ERROR: Argument number " + (i + 1) +
167 " (" + m_args[i].Name +
") must be a valid " +
168 m_args[i].ArgumentType.ToLower() +
".");
171 cleanArgs[i] = m_args[i].ArgumentValue;
176 m_command.Invoke(cleanArgs);
187 private string m_help;
188 private string m_name;
189 private string m_type;
201 get {
return m_name; }
204 public string HelpText
206 get {
return m_help; }
209 public string ArgumentType
211 get {
return m_type; }
214 public Object ArgumentValue
216 get {
return m_val; }
217 set { m_val = value; }
A single function call encapsulated in a class which enforces arguments when passing around as Object...
Interactive OpenSim region server
void AddArgument(string name, string helptext, string type)
CommandArgument(string name, string help, string type)
Command(string name, CommandIntentions intention, Action< Object[]> command, string help)
A single command argument, contains name, type and at runtime, value.