execute method

  1. @override
Future<void> execute(
  1. ArgResults results
)
override

Executes the command using the parsed results.

Implementation

@override
Future<void> execute(ArgResults results) async {
  final config = await ConfigService.load();

  if (!config.firebase.enabled) {
    LoggerService.error(
      'Firebase is disabled in fkit.yaml.',
    );
    return;
  }

  final target =
      results.rest.isNotEmpty ? results.rest.first : config.defaultFlavor;

  final platform = results['platform'] as String;

  final notes =
      results['notes'] as String? ?? 'Automated build upload via FKIT';

  final testerGroup =
      results['group'] as String? ?? config.firebase.testerGroup;

  if (!config.flavors.contains(target)) {
    LoggerService.error(
      'Target "$target" is not configured.',
    );
    return;
  }

  if (!PlatformUtils.isEnabled(config, platform)) {
    LoggerService.error(
      '$platform is disabled in fkit.yaml.',
    );
    return;
  }

  final firebase = config.firebase.configurationFor(target);

  if (firebase == null) {
    LoggerService.error(
      'Firebase configuration not found for target "$target".',
    );
    return;
  }

  final firebasePlatform = PlatformUtils.firebasePlatform(
    firebase,
    platform,
  );

  if (firebasePlatform == null) {
    LoggerService.error(
      '$platform Firebase configuration is not available '
      'for target "$target".',
    );
    return;
  }

  if (firebasePlatform.appId.isEmpty) {
    LoggerService.error(
      '$platform Firebase App ID is not configured '
      'for target "$target".',
    );
    return;
  }

  final buildResult = await BuildService().build(
    platform: PlatformUtils.buildPlatform(platform),
    flavor: target,
  );

  await FirebaseService().upload(
    appId: firebasePlatform.appId,
    artifactPath: buildResult.artifactPath,
    testerGroup: testerGroup,
    notes: notes,
  );

  LoggerService.blank();
  LoggerService.success(
    'Firebase upload completed successfully.',
  );
  LoggerService.blank();
}