* Add the ability to type help <command> for more detailed help about a specific command if any is available

0.6.3-post-fixes
Justin Clarke Casey 2009-02-09 20:52:04 +00:00
parent 66dc421be7
commit a034b640da
5 changed files with 137 additions and 19 deletions

View File

@ -38,27 +38,111 @@ namespace OpenSim.Framework.Console
public class Commands public class Commands
{ {
/// <summary>
/// Encapsulates a command that can be invoked from the console
/// </summary>
private class CommandInfo private class CommandInfo
{ {
/// <value>
/// The module from which this command comes
/// </value>
public string module; public string module;
/// <value>
/// Very short BNF description
/// </value>
public string help_text; public string help_text;
/// <value>
/// Longer one line help text
/// </value>
public string long_help; public string long_help;
/// <value>
/// Full descriptive help for this command
/// </value>
public string descriptive_help;
/// <value>
/// The method to invoke for this command
/// </value>
public CommandDelegate fn; public CommandDelegate fn;
} }
/// <value>
/// Commands organized by keyword in a tree
/// </value>
private Dictionary<string, Object> tree = private Dictionary<string, Object> tree =
new Dictionary<string, Object>(); new Dictionary<string, Object>();
public List<string> GetHelp() /// <summary>
{ /// Get help for the given help string
/// </summary>
/// <param name="helpParts">Parsed parts of the help string. If empty then general help is returned.</param>
/// <returns></returns>
public List<string> GetHelp(string[] cmd)
{
List<string> help = new List<string>(); List<string> help = new List<string>();
List<string> helpParts = new List<string>(cmd);
// Remove initial help keyword
helpParts.RemoveAt(0);
help.AddRange(CollectHelp(tree)); // General help
if (helpParts.Count == 0)
help.Sort(); {
help.AddRange(CollectHelp(tree));
help.Sort();
}
else
{
help.AddRange(CollectHelp(helpParts));
}
return help; return help;
} }
/// <summary>
/// See if we can find the requested command in order to display longer help
/// </summary>
/// <param name="helpParts"></param>
/// <returns></returns>
private List<string> CollectHelp(List<string> helpParts)
{
string originalHelpRequest = string.Join(" ", helpParts.ToArray());
List<string> help = new List<string>();
Dictionary<string, object> 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<string, Object>)
dict = (Dictionary<string, object>)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<string> CollectHelp(Dictionary<string, Object> dict) private List<string> CollectHelp(Dictionary<string, Object> dict)
{ {
@ -79,12 +163,37 @@ namespace OpenSim.Framework.Console
} }
return result; return result;
} }
/// <summary>
/// Add a command to those which can be invoked from the console.
/// </summary>
/// <param name="module"></param>
/// <param name="command"></param>
/// <param name="help"></param>
/// <param name="longhelp"></param>
/// <param name="fn"></param>
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) /// <summary>
/// Add a command to those which can be invoked from the console.
/// </summary>
/// <param name="module"></param>
/// <param name="command"></param>
/// <param name="help"></param>
/// <param name="longhelp"></param>
/// <param name="descriptivehelp"></param>
/// <param name="fn"></param>
public void AddCommand(
string module, string command, string help, string longhelp, string descriptivehelp, CommandDelegate fn)
{ {
string[] parts = Parser.Parse(command); string[] parts = Parser.Parse(command);
Dictionary<string, Object> current = tree; Dictionary<string, Object> current = tree;
foreach (string s in parts) foreach (string s in parts)
{ {
if (current.ContainsKey(s)) if (current.ContainsKey(s))
@ -105,10 +214,12 @@ namespace OpenSim.Framework.Console
if (current.ContainsKey(String.Empty)) if (current.ContainsKey(String.Empty))
return; return;
CommandInfo info = new CommandInfo(); CommandInfo info = new CommandInfo();
info.module = module; info.module = module;
info.help_text = help; info.help_text = help;
info.long_help = longhelp; info.long_help = longhelp;
info.descriptive_help = descriptivehelp;
info.fn = fn; info.fn = fn;
current[String.Empty] = info; current[String.Empty] = info;
} }
@ -285,7 +396,9 @@ namespace OpenSim.Framework.Console
{ {
DefaultPrompt = defaultPrompt; DefaultPrompt = defaultPrompt;
Commands.AddCommand("console", "help", "help", "Get command list", Help); Commands.AddCommand(
"console", "help", "help [<command>]",
"Get general command list or more detailed help on a specific command", Help);
} }
private void AddToHistory(string text) private void AddToHistory(string text)
@ -517,7 +630,7 @@ namespace OpenSim.Framework.Console
private void Help(string module, string[] cmd) private void Help(string module, string[] cmd)
{ {
List<string> help = Commands.GetHelp(); List<string> help = Commands.GetHelp(cmd);
foreach (string s in help) foreach (string s in help)
Output(s); Output(s);

View File

@ -142,7 +142,8 @@ namespace OpenSim
m_console.Commands.AddCommand("region", "save oar", m_console.Commands.AddCommand("region", "save oar",
"save oar <oar name>", "save oar <oar name>",
"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", m_console.Commands.AddCommand("region", "save inventory",
"save inventory <first> <last> <path> <file>", "save inventory <first> <last> <path> <file>",

View File

@ -203,14 +203,14 @@ namespace OpenSim
foreach (string topic in topics) foreach (string topic in topics)
{ {
m_console.Commands.AddCommand("plugin", "help "+topic, m_console.Commands.AddCommand("plugin", "help " + topic,
"help "+topic, "help " + topic,
"Get help on plugin command '"+topic+"'", "Get help on plugin command '" + topic + "'",
HandleCommanderHelp); HandleCommanderHelp);
m_console.Commands.AddCommand("plugin", topic, m_console.Commands.AddCommand("plugin", topic,
topic, topic,
"Execute subcommand for plugin '"+topic+"'", "Execute subcommand for plugin '" + topic + "'",
null); null);
ICommander commander = ICommander commander =
@ -221,8 +221,8 @@ namespace OpenSim
foreach (string command in commander.Commands.Keys) foreach (string command in commander.Commands.Keys)
{ {
m_console.Commands.AddCommand(topic, topic+" "+command, m_console.Commands.AddCommand(topic, topic + " " + command,
topic+" "+commander.Commands[command].ShortHelp(), topic + " " + commander.Commands[command].ShortHelp(),
String.Empty, HandleCommanderCommand); String.Empty, HandleCommanderCommand);
} }
} }

View File

@ -64,11 +64,12 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
public void Close() public void Close()
{ {
} }
public void ArchiveRegion(string savePath) 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(); new ArchiveWriteRequestPreparation(m_scene, savePath).ArchiveRegion();
} }
@ -80,7 +81,8 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
public void DearchiveRegion(string loadPath) 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(); new ArchiveReadRequest(m_scene, loadPath).DearchiveRegion();
} }

View File

@ -204,7 +204,9 @@ namespace OpenSim.Region.Environment.Modules.World.Permissions
m_bypassPermissions = val; 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);
} }
} }