run method

  1. @override
Future<void> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<void> run() async {
  final creds = Credentials.load();
  if (creds == null) {
    AppLogger.error(
      'Not logged in. Run `appflight login` or set APPFLIGHT_API_KEY.',
    );
    exit(ExitCodes.noCredentials);
  }

  try {
    final dio = ApiClient.instance.forKey(creds.apiKey);
    final resp = await dio.get(Endpoints.whoami);
    final data = resp.data['data'] as Map<String, dynamic>;

    final type = data['type'] as String? ?? '—';
    final tier = data['tier'] as String? ?? 'free';

    CliAnalytics.ins.logWhoami();
    AppLogger.info('uid:         ${data['uid']}');
    AppLogger.info('email:       ${data['email'] ?? '—'}');
    AppLogger.info('type:        $type');
    AppLogger.info('plan:        ${_planLabel(tier)}');
    AppLogger.info('auth source: ${data['authSource']}');
  } on DioException catch (e) {
    AppLogger.error(
      'Request failed: ${e.response?.statusCode} ${e.message}',
    );
    exit(ExitCodes.authRejected);
  }
}