renderCommand<T extends Object> method
Future<OutputContext>
renderCommand<T extends Object>(
- CommandOutput output, {
- required Operation<
T> operation, - required OutputWidget textOutputUi,
- OutputWidget? jsonOutputUi,
- OutputWidget? yamlOutputUi,
- OutputWidget? fallbackErrorUi,
Implementation
Future<OutputContext> renderCommand<T extends Object>(
CommandOutput output, {
required Operation<T> operation,
required OutputWidget textOutputUi,
OutputWidget? jsonOutputUi,
OutputWidget? yamlOutputUi,
OutputWidget? fallbackErrorUi,
}) async {
final exceptionHandlingUi = CommonClientExceptionsWidget(
baseCommand: baseCommand,
elseWidget: ExceptionHandlingWidget<FailureException>(
errorWidgetMaker: (e) => FailureExceptionWidget(e),
elseWidget: fallbackErrorUi,
),
);
final ui = <T>[] is List<Stream>
? CommandWidget.stream(
textOutputUi: textOutputUi,
jsonOutputUi: jsonOutputUi,
yamlOutputUi: yamlOutputUi,
textErrorUi: exceptionHandlingUi,
)
: CommandWidget.text(
textOutputUi: textOutputUi,
jsonOutputUi: jsonOutputUi,
yamlOutputUi: yamlOutputUi,
textErrorUi: exceptionHandlingUi,
);
final context = await output.render(operation: operation, ui: ui);
// Re-throw exceptions as appropriate so that Sentry reporting and process exit
// are performed.
final qe = context.find<QualifiedException>();
if (qe != null) {
if (qe.exception case final FailureException f) {
final nested = f.nestedException;
if (nested != null) {
throw UnexpectedErrorExitException(
f.reason,
nested,
f.nestedStackTrace,
);
}
throw ErrorExitException(f.reason, null, f.nestedStackTrace);
}
final exitException = commonClientExceptionExit(
qe.exception,
qe.stackTrace,
);
if (exitException != null) {
throw exitException;
}
Error.throwWithStackTrace(qe.exception, qe.stackTrace);
}
return context;
}