Esempio n. 1
0
        static void RunCommandHandlerIfPossible(ConsoleCommand cmdHandler, List <string> cmdArgs)
        {
            bool canRun = true;

            if (cmdHandler.Condition != null)
            {
                canRun = cmdHandler.Condition(cmdArgs);
            }

            if (canRun)
            {
                cmdHandler.Run(cmdArgs);
            }
        }
Esempio n. 2
0
 public Func <IList <string>, Task> this[string cmd, params string[] cmdArgNames]
 {
     set
     {
         Commands[cmd] = new ConsoleCommand()
         {
             Condition = ca =>
             {
                 bool result = ca.Count == cmdArgNames.Length;
                 if (!result)
                 {
                     WriteLnRed("Invalid arguments");
                     WriteLn("    Use   " + cmdArgNames.Aggregate(cmd, (acc, curr) => acc += " <" + curr + ">"));
                 }
                 return(result);
             },
             Run             = value,
             CommandArgNames = cmdArgNames
         };
     }
 }
Esempio n. 3
0
        void RunCommandHandlerIfPossible(ConsoleCommand cmdHandler, List<string> cmdArgs)
        {
            bool canRun = true;

            if (cmdHandler.Condition != null)
                canRun = cmdHandler.Condition(cmdArgs);

            if (canRun)
            {
                if(cmdHandler.StartProgressBar) StartProgressBar();
                cmdHandler.Run(cmdArgs).ContinueWith(task =>
                {
                    if (cmdHandler.StartProgressBar) StopProgressBar();
                    if (task.IsFaulted)
                        PrintException(task.Exception);
                });
            }
            else
                WriteLn("Something went wrong. Unable to run command");
        }
Esempio n. 4
0
 public Func<IList<string>, Task> this[string cmd, bool startProgressBar, params string[] cmdArgNames]
 {
     set
     {
         Commands[cmd] = new ConsoleCommand()
         {
             Condition = ca =>
             {
                 bool result = ca.Count == cmdArgNames.Length;
                 if (!result)
                 {
                     WriteLnRed("Invalid arguments");
                     WriteLn("    Use   " + cmdArgNames.Aggregate(cmd, (acc, curr) => acc += " <" + curr + ">"));
                 }
                 return result;
             },
             Run = value,
             CommandArgNames = cmdArgNames,
             StartProgressBar = startProgressBar
         };
     }
 }
Esempio n. 5
0
 public Func<IList<string>, Task> this[string cmd, Func<IList<string>, bool> condition = null]
 {
     set
     {
         Commands[cmd] = new ConsoleCommand() { Condition = condition, Run = value };
     }
 }
Esempio n. 6
0
        static void RunCommandHandlerIfPossible(ConsoleCommand cmdHandler, List<string> cmdArgs)
        {
            bool canRun = true;

            if (cmdHandler.Condition != null)
                canRun = cmdHandler.Condition(cmdArgs);

            if (canRun)
                cmdHandler.Run(cmdArgs);
        }