run method

  1. @override
Future<void> run()

Runs this command. Subclasses should instead override runWithConfig.

Implementation

@override
Future<void> run() async {
  final apiCloudClient = runner.serviceProvider.cloudApiClient;

  if (requireLogin &&
      await apiCloudClient.authenticationKeyManager?.isAuthenticated !=
          true) {
    logger.error('This command requires you to be logged in.');
    logger.terminalCommand(
      message: 'Please run the login command to authenticate and try again:',
      'scloud auth login',
    );
    throw ErrorExitException('This command requires you to be logged in.');
  }

  try {
    await super.run();
  } on FailureException catch (e, stackTrace) {
    _processFailureException(e, stackTrace);
  } on CloudCliUsageException catch (e, stackTrace) {
    // TODO: Don't catch CloudCliUsageException,
    // it's a UsageException and is handled by the caller.
    logger.error(e.message, hint: e.hint);
    throw ErrorExitException(e.message, e, stackTrace);
  } on UsageException catch (_) {
    rethrow;
  } on ErrorExitException catch (_) {
    rethrow;
  } on Exception catch (e, stackTrace) {
    processCommonClientExceptions(logger, e, stackTrace);
    logger.error(
      'Error when running command `$name`',
      exception: e,
      stackTrace: stackTrace,
    );
    throw ErrorExitException(e.toString(), e, stackTrace);
  }
}