* Fixed a small logical error in error handling of console commands.

* Console command help should be output to the console, not to the log (as "help" does it already). That allows getting help/answers even if you only log into a file.
Fixes Mantis#2916.
0.6.3-post-fixes
Homer Horwitz 2009-01-25 16:12:55 +00:00
parent aa2521623c
commit b405d92260
1 changed files with 22 additions and 16 deletions

View File

@ -41,7 +41,7 @@ namespace OpenSim.Region.Environment.Modules.Framework.InterfaceCommander
/// </summary> /// </summary>
public class Command : ICommand public class Command : ICommand
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private List<CommandArgument> m_args = new List<CommandArgument>(); private List<CommandArgument> m_args = new List<CommandArgument>();
private Action<object[]> m_command; private Action<object[]> m_command;
@ -94,13 +94,13 @@ namespace OpenSim.Region.Environment.Modules.Framework.InterfaceCommander
public void ShowConsoleHelp() public void ShowConsoleHelp()
{ {
m_log.Info("== " + Name + " =="); Console.WriteLine("== " + Name + " ==");
m_log.Info(m_help); Console.WriteLine(m_help);
m_log.Info("= Parameters ="); Console.WriteLine("= Parameters =");
foreach (CommandArgument arg in m_args) foreach (CommandArgument arg in m_args)
{ {
m_log.Info("* " + arg.Name + " (" + arg.ArgumentType + ")"); Console.WriteLine("* " + arg.Name + " (" + arg.ArgumentType + ")");
m_log.Info("\t" + arg.HelpText); Console.WriteLine("\t" + arg.HelpText);
} }
} }
@ -110,13 +110,13 @@ namespace OpenSim.Region.Environment.Modules.Framework.InterfaceCommander
if (args.Length < cleanArgs.Length) if (args.Length < cleanArgs.Length)
{ {
m_log.Error("Missing " + (cleanArgs.Length - args.Length) + " argument(s)"); Console.WriteLine("ERROR: Missing " + (cleanArgs.Length - args.Length) + " argument(s)");
ShowConsoleHelp(); ShowConsoleHelp();
return; return;
} }
if (args.Length > cleanArgs.Length) if (args.Length > cleanArgs.Length)
{ {
m_log.Error("Too many arguments for this command. Type '<module> <command> help' for help."); Console.WriteLine("ERROR: Too many arguments for this command. Type '<module> <command> help' for help.");
return; return;
} }
@ -125,7 +125,7 @@ namespace OpenSim.Region.Environment.Modules.Framework.InterfaceCommander
{ {
if (string.IsNullOrEmpty(arg.ToString())) if (string.IsNullOrEmpty(arg.ToString()))
{ {
m_log.Error("Empty arguments are not allowed"); Console.WriteLine("ERROR: Empty arguments are not allowed");
return; return;
} }
try try
@ -145,15 +145,16 @@ namespace OpenSim.Region.Environment.Modules.Framework.InterfaceCommander
m_args[i].ArgumentValue = Boolean.Parse(arg.ToString()); m_args[i].ArgumentValue = Boolean.Parse(arg.ToString());
break; break;
default: default:
m_log.Error("Unknown desired type for argument " + m_args[i].Name + " on command " + m_name); Console.WriteLine("ERROR: Unknown desired type for argument " + m_args[i].Name + " on command " + m_name);
break; break;
} }
} }
catch (FormatException) catch (FormatException)
{ {
m_log.Error("Argument number " + (i + 1) + Console.WriteLine("ERROR: Argument number " + (i + 1) +
" (" + m_args[i].Name + ") must be a valid " + " (" + m_args[i].Name + ") must be a valid " +
m_args[i].ArgumentType.ToLower() + "."); m_args[i].ArgumentType.ToLower() + ".");
return;
} }
cleanArgs[i] = m_args[i].ArgumentValue; cleanArgs[i] = m_args[i].ArgumentValue;
@ -289,22 +290,27 @@ namespace OpenSim.Region.Environment.Modules.Framework.InterfaceCommander
} }
else else
{ {
if (function != "help")
m_log.Error("Invalid command - No such command exists");
if (function == "api") if (function == "api")
{
m_log.Info(GenerateRuntimeAPI()); m_log.Info(GenerateRuntimeAPI());
}
else
{
if (function != "help")
Console.WriteLine("ERROR: Invalid command - No such command exists");
ShowConsoleHelp(); ShowConsoleHelp();
} }
} }
}
#endregion #endregion
private void ShowConsoleHelp() private void ShowConsoleHelp()
{ {
m_log.Info("===" + m_name + "==="); Console.WriteLine("===" + m_name + "===");
foreach (ICommand com in m_commands.Values) foreach (ICommand com in m_commands.Values)
{ {
m_log.Info("* " + com.Name + " - " + com.Help); Console.WriteLine("* " + com.Name + " - " + com.Help);
} }
} }