diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs index 380894dd45..ef9b224a9c 100644 --- a/OpenSim/Framework/Console/ConsoleBase.cs +++ b/OpenSim/Framework/Console/ConsoleBase.cs @@ -38,27 +38,111 @@ namespace OpenSim.Framework.Console public class Commands { + /// + /// Encapsulates a command that can be invoked from the console + /// private class CommandInfo { + /// + /// The module from which this command comes + /// public string module; + + /// + /// Very short BNF description + /// public string help_text; + + /// + /// Longer one line help text + /// public string long_help; + + /// + /// Full descriptive help for this command + /// + public string descriptive_help; + + /// + /// The method to invoke for this command + /// public CommandDelegate fn; } + /// + /// Commands organized by keyword in a tree + /// private Dictionary tree = new Dictionary(); - public List GetHelp() - { + /// + /// Get help for the given help string + /// + /// Parsed parts of the help string. If empty then general help is returned. + /// + public List GetHelp(string[] cmd) + { List help = new List(); + List helpParts = new List(cmd); + + // Remove initial help keyword + helpParts.RemoveAt(0); - help.AddRange(CollectHelp(tree)); - - help.Sort(); + // General help + if (helpParts.Count == 0) + { + help.AddRange(CollectHelp(tree)); + help.Sort(); + } + else + { + help.AddRange(CollectHelp(helpParts)); + } return help; } + + /// + /// See if we can find the requested command in order to display longer help + /// + /// + /// + private List CollectHelp(List helpParts) + { + string originalHelpRequest = string.Join(" ", helpParts.ToArray()); + List help = new List(); + + Dictionary dict = tree; + while (helpParts.Count > 0) + { + string helpPart = helpParts[0]; + + if (!dict.ContainsKey(helpPart)) + break; + + //System.Console.WriteLine("Found {0}", helpParts[0]); + + if (dict[helpPart] is Dictionary) + dict = (Dictionary)dict[helpPart]; + + helpParts.RemoveAt(0); + } + + // There was a command for the given help string + if (dict.ContainsKey(String.Empty)) + { + CommandInfo commandInfo = (CommandInfo)dict[String.Empty]; + help.Add(commandInfo.help_text); + help.Add(commandInfo.long_help); + help.Add(commandInfo.descriptive_help); + } + else + { + help.Add(string.Format("No help is available for {0}", originalHelpRequest)); + } + + return help; + } private List CollectHelp(Dictionary dict) { @@ -79,12 +163,37 @@ namespace OpenSim.Framework.Console } return result; } + + /// + /// Add a command to those which can be invoked from the console. + /// + /// + /// + /// + /// + /// + public void AddCommand( + string module, string command, string help, string longhelp, CommandDelegate fn) + { + AddCommand(module, command, help, longhelp, String.Empty, fn); + } - public void AddCommand(string module, string command, string help, string longhelp, CommandDelegate fn) + /// + /// Add a command to those which can be invoked from the console. + /// + /// + /// + /// + /// + /// + /// + public void AddCommand( + string module, string command, string help, string longhelp, string descriptivehelp, CommandDelegate fn) { string[] parts = Parser.Parse(command); Dictionary current = tree; + foreach (string s in parts) { if (current.ContainsKey(s)) @@ -105,10 +214,12 @@ namespace OpenSim.Framework.Console if (current.ContainsKey(String.Empty)) return; + CommandInfo info = new CommandInfo(); info.module = module; info.help_text = help; info.long_help = longhelp; + info.descriptive_help = descriptivehelp; info.fn = fn; current[String.Empty] = info; } @@ -285,7 +396,9 @@ namespace OpenSim.Framework.Console { DefaultPrompt = defaultPrompt; - Commands.AddCommand("console", "help", "help", "Get command list", Help); + Commands.AddCommand( + "console", "help", "help []", + "Get general command list or more detailed help on a specific command", Help); } private void AddToHistory(string text) @@ -517,7 +630,7 @@ namespace OpenSim.Framework.Console private void Help(string module, string[] cmd) { - List help = Commands.GetHelp(); + List help = Commands.GetHelp(cmd); foreach (string s in help) Output(s); diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 5bce2255bb..d706e05916 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -142,7 +142,8 @@ namespace OpenSim m_console.Commands.AddCommand("region", "save oar", "save oar ", - "Save a region's data to an OAR archive", SaveOar); + "Save a region's data to an OAR archive", + "More information on forthcoming options here soon", SaveOar); m_console.Commands.AddCommand("region", "save inventory", "save inventory ", diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 4d561477e3..d032864fe2 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -203,14 +203,14 @@ namespace OpenSim foreach (string topic in topics) { - m_console.Commands.AddCommand("plugin", "help "+topic, - "help "+topic, - "Get help on plugin command '"+topic+"'", + m_console.Commands.AddCommand("plugin", "help " + topic, + "help " + topic, + "Get help on plugin command '" + topic + "'", HandleCommanderHelp); m_console.Commands.AddCommand("plugin", topic, topic, - "Execute subcommand for plugin '"+topic+"'", + "Execute subcommand for plugin '" + topic + "'", null); ICommander commander = @@ -221,8 +221,8 @@ namespace OpenSim foreach (string command in commander.Commands.Keys) { - m_console.Commands.AddCommand(topic, topic+" "+command, - topic+" "+commander.Commands[command].ShortHelp(), + m_console.Commands.AddCommand(topic, topic + " " + command, + topic + " " + commander.Commands[command].ShortHelp(), String.Empty, HandleCommanderCommand); } } diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs index ed494fc411..cd811693bf 100644 --- a/OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs +++ b/OpenSim/Region/Environment/Modules/World/Archiver/ArchiverModule.cs @@ -64,11 +64,12 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver public void Close() { - } + } public void ArchiveRegion(string savePath) { - m_log.InfoFormat("[SCENE]: Writing archive for region {0} to {1}", m_scene.RegionInfo.RegionName, savePath); + m_log.InfoFormat( + "[ARCHIVER]: Writing archive for region {0} to {1}", m_scene.RegionInfo.RegionName, savePath); new ArchiveWriteRequestPreparation(m_scene, savePath).ArchiveRegion(); } @@ -80,7 +81,8 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver public void DearchiveRegion(string loadPath) { - m_log.InfoFormat("[SCENE]: Loading archive to region {0} from {1}", m_scene.RegionInfo.RegionName, loadPath); + m_log.InfoFormat( + "[ARCHIVER]: Loading archive to region {0} from {1}", m_scene.RegionInfo.RegionName, loadPath); new ArchiveReadRequest(m_scene, loadPath).DearchiveRegion(); } diff --git a/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs index e48ef13d83..8838e39fb9 100644 --- a/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs +++ b/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs @@ -204,7 +204,9 @@ namespace OpenSim.Region.Environment.Modules.World.Permissions m_bypassPermissions = val; - m_log.InfoFormat("[PERMISSIONS] Set permissions bypass to {0} for {1}", m_bypassPermissions, m_scene.RegionInfo.RegionName); + m_log.InfoFormat( + "[PERMISSIONS]: Set permissions bypass to {0} for {1}", + m_bypassPermissions, m_scene.RegionInfo.RegionName); } }