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 client = argResults!['client'] as String;
  final isTest = argResults!['test'] as bool;
  final config = ConfigService(projectDir);
  final appConfig = AppConfigService(projectDir, config);

  if (!appConfig.settings.isGenerated) {
    throw BuildException(
      'This project uses dotenv mode; there is no generated config file.',
      fix: 'Run "udara_cli migrate-config" to switch to generated config.',
    );
  }

  // A Run Client (--keep) backed up the file; restore the original project
  // first, or its next restore would bring the stale file back.
  await recoverInterruptedRun(
      CleanupService(projectDir: projectDir, config: config));

  final envFile = await resolveClientEnvFile(client, isTest: isTest);
  final file = appConfig.outputFile;
  final before = file.existsSync() ? file.readAsStringSync() : null;
  await appConfig.write(
      client: client,
      envFile: envFile,
      isTest: isTest,
      trackForCleanup: false);
  final output = appConfig.settings.output;
  final source = p.relative(envFile.path, from: projectDir);

  if (before == file.readAsStringSync()) {
    Logger.success('$output is already up to date ($source).');
  } else {
    Logger.success('Regenerated $output from $source.');
    if (client != WhiteLabelService.defaultClientName || isTest) {
      Logger.info('Commit the default client\'s version: run '
          '"udara_cli generate-config" before committing.');
    } else {
      Logger.info('Commit it so plain "flutter run" and the analyzer see '
          'the same fields.');
    }
  }

  if (!await appConfig.ensureOutputTracked()) {
    Logger.warning('git still ignores $output, so it is never committed and '
        'fresh clones don\'t compile. Check "git check-ignore -v $output".');
  }

  final leftOut = appConfig.keysMissingFromInclude();
  if (leftOut.isNotEmpty) {
    Logger.warning('Not compiled in because app_config.include in '
        'udara.yaml doesn\'t list them: ${leftOut.join(', ')}. Add the '
        'ones the app reads (they are null at runtime until you do).');
  }
}