public void StartApp(IConsoleApp app, Stream input, Stream output, bool enableEcho, string parameters) { if (input == null) { input = new AppInputStream(); } if (output == null) { var session = ConsoleManager.Controller.CreateSeason(); output = new AppOutputStream(session); } app.Console.Input = input; app.Console.Output = output; app.Console.EnableEcho = enableEcho; app.AppManager = this; SetCurrentApplication(app); app.Start(parameters); }
/// <summary> /// Creates a console object, fills it from the default command-line arguments, then calls its Start method. Also supports Click-Once deployed URL arguments. /// </summary> /// <param name="options">Options for how to handle running the console app.</param> public static void Start <T>(BaConStartOptions options = null) where T : IConsoleApp, new() { if (options == null) { options = new BaConStartOptions(); } IConsoleApp consoleApp = null; try { var results = ParseArgs <T>(options.CmdLineOptions); consoleApp = results.Args; if (results.Title.HasValue()) { WriteLine(results.Title, Theme.AppTitleColor); } if (results.Description.HasValue()) { WriteLine(results.Description, Theme.AppDescriptionColor); } if (results.Copyright.HasValue()) { WriteLine(results.Copyright.Replace("©", "(c)"), Theme.AppDescriptionColor); // The © doesn't show up correctly in the console. } WriteLine(); // Put a line between the title and rest of the information. // Validate only after checking to see if they requested help // in order to prevent displaying errors when they request help. if (consoleApp.Help || results.Errors.Length > 0) { WriteHelp(results); if (!consoleApp.Help && results.Errors.Length > 0) { Environment.ExitCode = options.CmdLineOptions.InvalidArgsExitCode ?? 1; // There were errors, return exit code. } else { Environment.ExitCode = 0; } return; } Environment.ExitCode = consoleApp.Start(); } catch (Exception ex) { if (consoleApp == null || !consoleApp.Error(ex)) { WriteError(ex); Environment.ExitCode = options?.CmdLineOptions?.FatalErrorExitCode ?? -1; } } finally { if (consoleApp != null && consoleApp.Wait) { WriteLine(options.PressAnyKey); Console.ReadKey(); } // Dispose of the app if it is disposable. (consoleApp as IDisposable)?.Dispose(); } }
public void StartApp(IConsoleApp app, Stream input, Stream output, bool enableEcho, string parameters) { if (input == null) { input = new AppInputStream(); } if (output == null) { var session = Mosa.Kernel.x86.ConsoleManager.Controller.CreateSeason(); output = new AppOutputStream(session); } app.Console.Input = input; app.Console.Output = output; app.Console.EnableEcho = enableEcho; app.AppManager = this; SetCurrentApplication(app); app.Start(parameters); }