run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<void> run() async {
config = ConfigService(projectDir);
final clientA = argResults!['client-a'] as String;
final clientB = argResults!['client-b'] as String;
final isTest = argResults!['test'] as bool;
final showAll = argResults!['all'] as bool;
final envFileName = isTest ? '.env_test' : '.env';
final envFileA = File(p.join(projectDir, 'clients', clientA, envFileName));
final envFileB = File(p.join(projectDir, 'clients', clientB, envFileName));
if (!envFileA.existsSync()) {
throw BuildException(
'$envFileName not found for client "$clientA"',
fix: 'Run "udara_cli setup --clients $clientA" to create it.',
);
}
if (!envFileB.existsSync()) {
throw BuildException(
'$envFileName not found for client "$clientB"',
fix: 'Run "udara_cli setup --clients $clientB" to create it.',
);
}
final varsA = await config.parseEnvFile(envFileA);
final varsB = await config.parseEnvFile(envFileB);
final allKeys = <String>{...varsA.keys, ...varsB.keys}.toList()..sort();
Logger.phase('Comparing "$clientA" vs "$clientB" ($envFileName)');
var differenceCount = 0;
for (final key in allKeys) {
final valueA = varsA[key];
final valueB = varsB[key];
final differs = valueA != valueB;
if (differs) differenceCount++;
if (!differs && !showAll) continue;
final displayA = valueA ?? '(not set)';
final displayB = valueB ?? '(not set)';
if (differs) {
Logger.warning('$key');
Logger.info(' $clientA: $displayA');
Logger.info(' $clientB: $displayB');
} else {
Logger.success('$key: $displayA');
}
}
Logger.phase('Summary');
if (differenceCount == 0) {
Logger.success('No differences found between "$clientA" and "$clientB".');
} else {
Logger.info(
'$differenceCount key(s) differ between "$clientA" and "$clientB".');
}
}