confirmToContinue method

Future<void> confirmToContinue(
  1. CommandOutput output, {
  2. required String message,
  3. bool? defaultValue,
})

Confirms with the user whether to continue with the action.

Throws a UserAbortException if the user does not confirm. Throws a CloudCliUsageException if the configured format and interaction mode is not supported.

Implementation

Future<void> confirmToContinue(
  final CommandOutput output, {
  required final String message,
  final bool? defaultValue,
}) async {
  if (globalConfiguration.skipConfirmation == true) {
    return;
  }

  if (output.format.isStructured) {
    // TODO: Add custom validation group to --yes and --format options when --format is made global
    throw CloudCliUsageException(
      'Interactive UI is not supported with structured format "${output.format.name}".',
      hint: 'Use "--yes" with "--format json|yaml" for interactive commands.',
    );
  }

  final confirmed = await output.renderInteractive(
    ui: ConfirmationWidget(message, defaultValue: defaultValue),
  );
  if (!confirmed) {
    throw UserAbortException();
  }
}