private static async Task RunAndExitAsync(this TargetCollection targets, List <string> args, Func <Exception, bool> messageOnly, string logPrefix) { var(names, options) = args.Parse(); var(output, log) = await ConsoleExtensions.Initialize(options, logPrefix).Tax(); try { await RunAsync(targets, names, options, output, log, messageOnly, args).Tax(); } catch (InvalidUsageException ex) { await log.Error(ex.Message).Tax(); Environment.Exit(2); } catch (TargetFailedException) { Environment.Exit(1); } Environment.Exit(0); }