static void RunCommandHandlerIfPossible(ConsoleCommand cmdHandler, List <string> cmdArgs) { bool canRun = true; if (cmdHandler.Condition != null) { canRun = cmdHandler.Condition(cmdArgs); } if (canRun) { cmdHandler.Run(cmdArgs); } }
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 }; } }
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"); }
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 }; } }
public Func<IList<string>, Task> this[string cmd, Func<IList<string>, bool> condition = null] { set { Commands[cmd] = new ConsoleCommand() { Condition = condition, Run = value }; } }
static void RunCommandHandlerIfPossible(ConsoleCommand cmdHandler, List<string> cmdArgs) { bool canRun = true; if (cmdHandler.Condition != null) canRun = cmdHandler.Condition(cmdArgs); if (canRun) cmdHandler.Run(cmdArgs); }