13 public static CommandLineBuilder
UseToolParseError(
this CommandLineBuilder builder,
int? errorExitCode =
null)
15 return builder.AddMiddleware(OnParseErrorReporting(errorExitCode), MiddlewareOrder.ErrorReporting);
18 static InvocationMiddleware OnParseErrorReporting(
int? errorExitCode)
20 return async (context, next) =>
22 if (context.ParseResult.Errors.Count > 0)
31 return builder.UseExceptionHandler(OnException, 1);
34 static void OnException(Exception exception, InvocationContext context)
38 var terminal = Terminal.GetTerminal(context.Console);
39 terminal.Render(
new ContainerSpan(ForegroundColorSpan.Red(),
new ContentSpan(e.Message), ForegroundColorSpan.Reset()));
44 ExceptionDispatchInfo.Capture(exception).Throw();