Exemplo n.º 1
0
            public void Invoke(string data)
            {
                var args = DeveloperConsole.SplitArgs(data);

                if (args.Length != 0)
                {
                    LogWarning(Help);
                }
                else
                {
                    DeveloperConsole.Log(DeveloperConsole.WorkingDirectory);
                }
            }
Exemplo n.º 2
0
            public void Invoke(string data)
            {
                var args = DeveloperConsole.SplitArgs(data);

                if (args.Length > 1)
                {
                    LogWarning(kUsage);
                    return;
                }

                string dirPath;

                if (args.Length == 1)
                {
                    if (!TryNavigateDirectory(args[0], out dirPath))
                    {
                        // Inputted directory does not exist
                        LogWarning("not a directory");
                        return;
                    }
                }
                else
                {
                    dirPath = DeveloperConsole.WorkingDirectory;
                }

                // Get all directories and files in the current path and alphabetize
                var entries = Directory.GetFileSystemEntries(dirPath, "*", SearchOption.TopDirectoryOnly)
                              .OrderBy(e => e);

                // Write directories to console
                StringBuilder sb = new StringBuilder();

                foreach (var entry in entries)
                {
                    ConsoleUtilities.TryGetRelative(dirPath, entry, out var formatted);
                    if (Directory.Exists(entry))
                    {
                        formatted = $"<color=#{kDirectoryColorHtml}>{formatted}</color>";
                    }
                    sb.AppendLine(formatted);
                }

                DeveloperConsole.Log(sb.ToString());
            }
Exemplo n.º 3
0
        public void Invoke(string data)
        {
            var args = DeveloperConsole.SplitArgs(data);

            if (args.Length == 0)
            {
                Invoke();
            }
            else
            {
                // Find a verb whose name is the first argument
                var verb = args[0].Trim().ToLower();

                foreach (var pair in mVerbs)
                {
                    if (pair.Key.Equals(verb))
                    {
                        pair.Value.Command.Invoke(data.Substring(DeveloperConsole.SplitPositions[0]));
                        return;
                    }
                }

                // No verb with that name
                DeveloperConsole.LogWarning($"'{Name}': no such verb with name '{args[0]}' could be found.");
                if (mVerbs.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Possible subcommands are: ");
                    var verbsAlphabetized = (from pair in mVerbs
                                             let v = pair.Value
                                                     orderby v.Name
                                                     select v);

                    foreach (var v in verbsAlphabetized)
                    {
                        sb.AppendLine($"    * {Name} {v.Name}");
                    }
                    DeveloperConsole.LogWarning(sb.ToString());
                }
            }
        }
Exemplo n.º 4
0
            public void Invoke(string data)
            {
                var args = DeveloperConsole.SplitArgs(data);

                if (args.Length == 0)
                {
                    DeveloperConsole.ChangeDirectory(DeveloperConsole.HomeDirectory);
                }
                else if (args.Length == 1)
                {
                    if (TryNavigateDirectory(args[0], out var newDir))
                    {
                        DeveloperConsole.ChangeDirectory(newDir);
                    }
                    else
                    {
                        LogWarning("not a directory");
                    }
                }
                else
                {
                    LogWarning(kUsage);
                }
            }
Exemplo n.º 5
0
        public void Invoke(string data)
        {
            var args = DeveloperConsole.SplitArgs(data);

            if (args.Length > 1)
            {
                LogWarning(kUsage);
            }
            if (args.Length == 0)
            {
                // No arguments provided, list all commands

                // Sort commands alphabetically
                var commands = from command in DeveloperConsole.Commands
                               orderby command.Name
                               select command;

                const int kRichTextMargin    = 23;              // Add characters for the additional <color=#xxxxxx></color> rich text tags
                var       commandColumnWidth = commands.Select(command => command.Name).Max(name => name.Length) + kIndent;

                // Compile string of all commands and descriptions
                StringBuilder sb = new StringBuilder();

                string essentialRowFormat = $"{{0,{-commandColumnWidth - kRichTextMargin}}}{{1}}";
                string rowFormat          = $"{{0,{-commandColumnWidth}}}{{1}}";

                foreach (var command in commands)
                {
                    string commandName = command.Name;

                    // Show commands in a special color if they are essential
                    if (command.Essential)
                    {
                        commandName = $"<color=#{kEssentialColor}>{commandName}</color>";
                    }

                    if (string.IsNullOrWhiteSpace(command.Description))
                    {
                        sb.AppendLine(command.Name);                                                                     // No description, so don't print it
                    }
                    else
                    {
                        // There is a description. Split it into lines and then print it out with the proper column indentation
                        var lines = Regex.Split(command.Description, "\r\n|\r|\n");
                        sb.AppendLine(string.Format(command.Essential ? essentialRowFormat : rowFormat, commandName, lines[0]));
                        for (int i = 1; i < lines.Length; i++)
                        {
                            sb.AppendLine(string.Format(rowFormat, string.Empty, lines[i]));
                        }
                    }
                }
                DeveloperConsole.Log(sb.ToString());
            }
            else if (args.Length == 1)
            {
                var cmdName  = args[0].Trim().ToLower();
                var commands = DeveloperConsole.Console.mCommands;

                foreach (var pair in commands)
                {
                    if (pair.Key.Equals(cmdName))
                    {
                        var description = pair.Value.Description;
                        var help        = pair.Value.Command.Help;

                        if (string.IsNullOrWhiteSpace(description))
                        {
                            if (string.IsNullOrWhiteSpace(help))
                            {
                                // No description or help text was provided with this command. Notify the user.
                                DeveloperConsole.Log($"No help information provided for <b>{pair.Key}</b>");
                            }
                            else
                            {
                                // Help was provided, but no description
                                // Just print help text
                                DeveloperConsole.Log(help);
                            }
                        }
                        else
                        {
                            if (string.IsNullOrWhiteSpace(help))
                            {
                                // A description was provided, but no help.
                                // Just print description
                                DeveloperConsole.Log($"<b>{pair.Key}:</b> {description}");
                            }
                            else
                            {
                                // Both a description and help text were provided.
                                // Print both with a paragraph break between
                                DeveloperConsole.Log($"<b>{pair.Key}:</b> {description}\n\n{help}");
                            }
                        }

                        return;
                    }
                }

                // No command found
                LogWarning($"'{cmdName}' is not a command");
            }
        }