Example #1
0
        static void Main(string[] args)
        {
            DelegateCommandDescriptionProvider provider =
                new DelegateCommandDescriptionProvider();

            provider.AddCommand("Exit")
                    .OnExecute((cmd, dict) => Environment.Exit(0));

            provider.AddCommand("Write")
                    .WithArgument<string>("text")
                    .IsDefault()
                    .WithAlias("-text")
                    .WithAlias("/text:")
                    .WithArgument<bool>("yellow")
                    .WithAlias("/yellow")
                    .IsOptional()
                    .OnExecute((cmd, dict) =>
                                   {
                                       if (dict.ContainsKey("yellow"))
                                       {
                                           Console.ForegroundColor =
                                               ConsoleColor.Yellow;
                                       }

                                       Console.WriteLine(dict["text"]);

                                       if (dict.ContainsKey("yellow"))
                                       {
                                           Console.ForegroundColor =
                                               ConsoleColor.Gray;
                                       }
                                   });

            CommandPrompt prompt =
                new CommandPrompt(new List<ICommandDescriptionProvider>()
                                      {
                                          provider
                                      });

            while (true)
            {
                Console.Write("> ");
                string line = Console.ReadLine();
                prompt.Execute(line);
            }
        }
Example #2
0
 public CommandDetails(CommandPrompt prompt, IDictionary<string, object> arguments)
 {
     mPrompt = prompt;
     mArguments = arguments;
 }
Example #3
0
 public DelegateCommand(CommandPrompt cmd, IDictionary<string, object> arguments, Action<CommandPrompt, IDictionary<string, object>> executer)
 {
     mCmd = cmd;
     mArguments = arguments;
     mExecuter = executer;
 }