Exemplo n.º 1
0
        public static void Cmd_Help_Handler_General(Command.Exec e, Dictionary <string, Command> commandLookup)
        {
            Arguments args = Arguments.Parse(e.cmd, e.tok, e.src);

            //Show.Log(args);
            if (!args.TryGet("-c", out string commandName))
            {
                Cmd_Help.General_Handler(e, commandLookup);
            }
            else
            {
                commandLookup.TryGetValue(commandName, out Command cmd);
                Cmd_Help.Command_Handler(e, commandName, cmd);
            }
        }
Exemplo n.º 2
0
            public static void General_Handler(Command.Exec e, Dictionary <string, Command> commandTable)
            {
                RecalculateColor();
                List <Command> commands = new List <Command>();

                foreach (KeyValuePair <string, Command> kvp in commandTable)
                {
                    commands.Add(kvp.Value);
                }
                commands.Sort((a, b) => a.Name.CompareTo(b.Name));
                for (int i = 0; i < commands.Count; ++i)
                {
                    Command cmd      = commands[i];
                    string  colorTxt = ColorFor(cmd.devState, colorCommand);
                    string  line     = $"{colorTxt}{cmd.Name}{colorStd} : {colorDescription}{cmd.description}{colorStd}\n";
                    e.print.Invoke(line);
                }
                string extraInstructions = $"for more information, type {colorCommand}help {colorOptional}-c {colorArgument}nameOfCommand{colorStd}\n";

                e.print.Invoke(extraInstructions);
            }
Exemplo n.º 3
0
            public static void Command_Handler(Command.Exec e, string commandName, Command command)
            {
                RecalculateColor();
                if (command == null)
                {
                    string error = $"{colorDescription}unknown command {colorError}{commandName}{colorStd}\n";
                    e.print.Invoke(error);
                    return;
                }
                string          colorTxt = ColorFor(command.devState, colorCommand);
                string          line     = $"Usage: {colorTxt}{command.Name}{colorStd}";
                List <Argument> args     = new List <Argument>();

                if (command.arguments != null)
                {
                    for (int i = 0; i < command.arguments.Length; ++i)
                    {
                        args.Add(command.arguments[i]);
                    }
                    line += colorArgument;
                }
                else
                {
                    line += $" {colorDescription}(no arguments){colorStd}";
                }
                args.Sort((a, b) => {
                    if (a.order > 0)
                    {
                        return((b.order > 0) ? a.order.CompareTo(b.order) : -1);
                    }
                    else if (b.order > 0)
                    {
                        return(1);
                    }
                    return(0);
                });
                for (int i = 0; i < args.Count; ++i)
                {
                    line += " ";
                    Argument arg = args[i];
                    char     open = '[', close = ']';
                    if (arg.required)
                    {
                        open = '<'; close = '>';
                    }
                    if (arg.order > 0 && arg.required)
                    {
                        open = '\0'; close = '\0';
                    }
                    if (open != '\0')
                    {
                        line += open;
                    }
                    //if (arg.order <= 0 || arg.flag) {
                    if (arg.order > 0)
                    {
                        line += colorOptional;
                    }
                    line += arg.id;
                    if (arg.order > 0)
                    {
                        line += colorArgument;
                    }
                    if (!arg.flag)
                    {
                        line += ' ';
                    }
                    //}
                    if (!arg.flag)
                    {
                        line += $"{arg.Name}{colorType}({arg.valueType.ToString().SubstringAfterLast(".")}){colorArgument}";
                    }
                    if (close != '\0')
                    {
                        line += close;
                    }
                }
                e.print.Invoke(line + "\n");
                for (int i = 0; i < args.Count; ++i)
                {
                    Argument arg = args[i];
                    colorTxt = ColorFor(arg.devState, colorArgument);
                    line     = $"{colorTxt}{arg.id} {colorStd}{arg.Name} : ";
                    if (!arg.flag)
                    {
                        line += $"{colorType}({arg.valueType.ToString().SubstringAfterLast(".")}) ";
                    }
                    line += $"{colorDescription}{arg.description}{colorStd}\n";
                    e.print.Invoke(line);
                }
                colorTxt = ColorFor(command.devState, colorCommand);
                line     = $"{colorTxt}{command.Name}{colorStd} : {colorDescription}{command.description}{colorStd}\n";
                e.print.Invoke(line);
            }
Exemplo n.º 4
0
 public void Cmd_Help_Handler(Command.Exec e)
 {
     Cmd_Help_Handler_General(e, commandLookup);
 }