Wenzil / UnityConsole

Easy-to-use developer console for Unity 5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Changed CustomCommands to provide a list all commands command

8Keep opened this issue · comments

I changed the example CustomCommands.cs's "Help" command to provide a list of all available commands, their description, and their usage when "Help" is entered without any other args. Here is the new help method:

private static string Help(params string[] args)
    {
        // if we got it wrong, get help about the HELP command
        if (args.Length == 0)
        {
            String commands = "";
            List<KeyValuePair<string, ConsoleCommand>> list = ConsoleCommandsDatabase.database.ToList();

            foreach (KeyValuePair<string, ConsoleCommand> pair in list)
            {

                commands += string.Format (
                    "{0}: {1} Usage: {2}\n", pair.Key, 
                    pair.Value.description, 
                    pair.Value.usage);
            }
            return Help("HELP") + "\nList of available commands:\n" + commands;
        }

        // if we got it right, get help about the given command
        string commandToGetHelpAbout = args[0].ToUpper();
        ConsoleCommand found;
        if(ConsoleCommandsDatabase.TryGetCommand(commandToGetHelpAbout, out found))
            return string.Format("Help information about {0}\n\r\tDescription: {1}\n\r\tUsage: {2}", commandToGetHelpAbout, found.description, found.usage);
        else
            return string.Format("Cannot find help information about {0}. Are you sure it is a valid command?", commandToGetHelpAbout);
    }

That's a good idea. I'll include it as a built-in command in the next release (0.2.0).