Beispiel #1
0
    public void ProcessCommand(string cmd, string[] cmdArgs)
    {
        Type commandType = CommandRegistry.GetCommandType(cmd);

        if (commandType == null)
        {
            Console.WriteLine("Unknown command: " + cmd);
            return;
        }

        Command command = (Command)Activator.CreateInstance(commandType, new object[] { this, cmdArgs });

        command.Run();
    }
Beispiel #2
0
    public void ProcessCommand(string cmd, string[] cmdArgs)
    {
        Type commandType = CommandRegistry.GetCommandType(cmd);

        if (commandType == null)
        {
            Console.WriteLine("Unknown command: " + cmd);
            Environment.Exit((int)ExitCode.UnrecognizedCommand);
        }

        Command command = (Command)Activator.CreateInstance(commandType, new object[] { this, cmdArgs });

        command.Run();
    }
Beispiel #3
0
    public void ShowCommandHelp(string cmd)
    {
        CommandAttribute attr = CommandRegistry.GetCommandAttribute(cmd);

        if (attr == null)
        {
            Console.WriteLine("Unknown command: " + cmd);
            Console.WriteLine();
            ShowHelp();
            return;
        }

        ShowCommandHelp(attr, "");
        Console.WriteLine("Usage: " + cmd + " " + attr.Args);
        Console.WriteLine();
        Console.WriteLine("Options:");

        Type commandType = CommandRegistry.GetCommandType(cmd);

        foreach (MemberInfo mi in commandType.GetMembers())
        {
            if (mi.MemberType != MemberTypes.Field)
            {
                continue;
            }

            OptionAttribute[] attribs = mi.GetCustomAttributes(typeof(OptionAttribute), true) as OptionAttribute[];
            if (attribs == null || attribs.Length == 0)
            {
                continue;
            }

            foreach (OptionAttribute attrib in attribs)
            {
                Type fieldType = ((FieldInfo)mi).FieldType;
                if (!String.IsNullOrEmpty(attrib.AlternateForm))
                {
                    string altform = "  /" + attrib.AlternateForm + "";
                    if (fieldType != typeof(bool))
                    {
                        altform += ":ARG";
                    }
                    Console.Write(altform.PadRight(20));
                }

                Console.Write("\t" + attrib.ShortDescription);

                if (!String.IsNullOrEmpty(attrib.LongForm))
                {
                    Console.Write(" (also /" + attrib.LongForm);
                    if (fieldType != typeof(bool))
                    {
                        Console.Write(":ARG");
                    }
                    Console.Write(")");
                }

                Console.WriteLine();
            }
        }

        Console.WriteLine();
    }