public int Run() { Log = Log ?? Loggy.Default; while (true) { try { _context.Write("> "); var command = _context.ReadLine(); if (string.IsNullOrWhiteSpace(command)) { continue; } if (command == "sync") { CheckTasks(true); continue; } if (command == "exit" || command == "quit") { try { CheckTasks(true); } catch { } return(0); } CheckTasks(); var task = Call(command); PendingTasks.Add(task); Thread.Sleep(10); CheckTasks(); Console.WriteLine(); } catch (AggregateException ae) { Log.Error(ae.InnerExceptions.FirstOrDefault()); } catch (Exception e) { Log.Error(e); } } }
public static CommandLine ParseCommandLine(IConsoleContext consoleContext, params string[] args) { if (args.Length == 0) { return(CommandLine.Help); } var toolAction = ToolAction.Help; VsVersion?version = null; string product = null; var rootSuffix = ""; var defaultDomain = false; var arg = ""; int index = 0; while (index < args.Length) { switch (args[index].ToLower()) { case "/i": case "/install": if (index + 1 >= args.Length) { consoleContext.Write("/install requires an argument"); return(CommandLine.Help); } toolAction = ToolAction.Install; arg = args[index + 1]; index += 2; break; case "/u": case "/uninstall": if (index + 1 >= args.Length) { consoleContext.Write("/uninstall requires an argument"); return(CommandLine.Help); } toolAction = ToolAction.Uninstall; arg = args[index + 1]; index += 2; break; case "/v": case "/version": if (index + 1 >= args.Length) { consoleContext.Write("/version requires an argument"); return(CommandLine.Help); } version = VsVersionUtil.ToVsVersion(args[index + 1]); index += 2; break; case "/p": case "/product": if (index + 1 >= args.Length) { consoleContext.Write("/product requires an argument"); return(CommandLine.Help); } product = args[index + 1]; index += 2; break; case "/r": case "/rootsuffix": if (index + 1 >= args.Length) { consoleContext.Write("/rootSuffix requires an argument"); return(CommandLine.Help); } rootSuffix = args[index + 1]; index += 2; break; case "/defaultdomain": defaultDomain = true; index++; break; case "/l": case "/list": toolAction = ToolAction.List; if (index + 1 < args.Length) { arg = args[index + 1]; } index = args.Length; break; case "/help": toolAction = ToolAction.Help; index = args.Length; break; default: arg = args[index]; if (!arg.StartsWith("/") && args.Length == 1) { // Default to Install if there's a single argument. toolAction = ToolAction.Install; index += 1; break; } consoleContext.WriteLine("{0} is not a valid argument", arg); return(CommandLine.Help); } } return(new CommandLine(toolAction, version, product, rootSuffix, arg, defaultDomain: defaultDomain)); }
public static void Write(this IConsoleContext consoleContext, string text, params object[] args) { consoleContext.Write(string.Format(text, args)); }