コード例 #1
0
ファイル: CLI.cs プロジェクト: Krzysiek0007/My-app
        public static void RunInteractiveMode(ICollection <IPlugin> plugins, string arg)
        {
            log.Information("Running app with a parameter: " + arg);

            bool shouldfinish           = false;
            ConsoleCommandHolder holder = new ConsoleCommandHolder();

            holder.AddRange(new ConsoleCommand[] { new SimpleCommand("Stop application", new string[] { "stop" },
                                                                     (x) =>
                {
                    Console.WriteLine("Do you really want to stop? (type 'yes' to stop)");
                    string acceptString = Console.ReadLine();
                    if (acceptString == "yes")
                    {
                        shouldfinish = true;
                    }
                }),
                                                   new SimpleCommand("HELP", new string[] { "help" }, (x) => DisplayHelpWithLogging()), });

            foreach (var plugin in plugins)
            {
                holder.Add(new SimpleCommand(plugin.Name, new string[] { plugin.Name.ToLower() }, (x) => ExecutePlugin(plugin)));
            }

            while (shouldfinish == false)
            {
                string         command   = Console.ReadLine();
                ConsoleCommand toExecute = holder.Find(command);
                if (toExecute != null)
                {
                    toExecute.Do(command);
                }
                else
                {
                    Console.WriteLine(holder);
                }
            }
        }
コード例 #2
0
 public void Add(ConsoleCommand toAdd)
 {
     unique.Add(toAdd);
 }