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 {
final configPath = argResults!['config'] as String;
final file = File(configPath);
if (!file.existsSync()) {
stderr.writeln('Config file not found: $configPath');
exit(1);
}
final yaml = loadYaml(file.readAsStringSync()) as Map;
final config = BlueprintConfig.fromYaml(yaml);
final targetDir = argResults!['output'] as String? ?? config.outputDir;
await Directory(targetDir).create(recursive: true);
print('Applying "${config.name}" ā $targetDir\n');
var step = 0;
var total = 0;
final bridge = EngineBridge(onMessage: (msg) {
if (msg is ProgressMessage) {
step = msg.step;
total = msg.total;
stdout.write('\r [$step/$total] ${msg.pack.padRight(20)}');
} else if (msg is LogMessage && msg.level == 'error') {
stderr.writeln('\n ā ${msg.message}');
}
});
try {
final ok = await bridge.run(config, targetDir);
if (total > 0) print(''); // newline after progress
if (ok) {
print('\nā Done! Created in $targetDir');
print('');
print('Next steps:');
print(' cd $targetDir');
print(' flutter pub get');
print(' flutter run');
} else {
stderr.writeln('\nā Apply failed.');
exit(1);
}
} catch (e) {
stderr.writeln('\nEngine error: $e');
exit(1);
}
}