示例#1
0
        public void Invoke(string rawInput)
        {
            //Split all values by space.
            var split = rawInput.Split(' ');
            //Get the name (command) value.
            var name = split[0];
            //Parse commands back into a string ignoring the first (name/command) value.
            var rawArgs           = split.Skip(1).ToString();
            CommandArguments args = null;

            //If raw args is null, empty, or has whitespace.
            if (rawArgs == "" || rawArgs == null)
            {
                args = new CommandArguments();
            }
            else
            {
                args = new CommandArguments(rawArgs.Split(' '));
            }
            //Finally get command.
            var cmd = GetCommand(name);

            if (cmd == null)
            {
                Console.WriteLine($"\"{name}\", is not a valid internal or external command.");
            }
            else if ((name == "--version" || name == "-ver") && cmd == null)
            {
                //Display version.
                if (processor.ApplicationName.GetCopyright() == null || processor.ApplicationName.GetCopyright() == CommandCopyright.EMPTY)
                {
                    Console.WriteLine(
                        $"~~~~~~~~~~~~~~~~~~~~\n\n" +
                        $"{processor.ApplicationName.GetName()} Version: {processor.ApplicationName.GetVersion()}\n" +
                        $"\n~~~~~~~~~~~~~~~~~~~~\n"
                        );
                }
                else
                {
                    Console.WriteLine(
                        $"~~~~~~~~~~~~~~~~~~~~\n\n" +
                        $"{processor.ApplicationName.GetCopyright().ToString()}\n" +
                        $"{processor.ApplicationName.GetName()} Version: {processor.ApplicationName.GetVersion()}\n" +
                        $"\n~~~~~~~~~~~~~~~~~~~~\n"
                        );
                }
            }
            else
            {
                //Invoke the specified commands.
                if (!(cmd.CommandCopyright() == CommandCopyright.EMPTY || cmd.CommandCopyright() == null))
                {
                    Console.WriteLine(cmd.CommandCopyright().ToString());
                }

                cmd.OnInvoke(this, args);
                if (cmd.ThrowSyntax)
                {
                    Console.WriteLine($"USAGE:\nLEGEND: '[]: Optional', '<>: Required', '| or ||: Or', and '& and &&: And'.\n{cmd.CommandSyntax()}");
                }
            }
        }
示例#2
0
 public abstract void OnInvoke(CommandInvoker invoker, CommandArguments args);