run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<int> run() async {
final ctx = await context;
final assets = await _resolveAssets(ctx);
final output = optional('output') ?? '.';
// More than one artifact has no single filename to be written to, so the
// output names a directory — created if it does not exist, because
// `--platform all -o dist/` is the natural way to spell a release bundle.
final intoDirectory = assets.length > 1 || await Directory(output).exists();
if (assets.length > 1) await Directory(output).create(recursive: true);
final manager = DownloadManager();
try {
for (final asset in assets) {
final destination = intoDirectory ? p.join(output, asset.name) : output;
final code = await _fetchOne(ctx, manager, asset, destination);
// Stops at the first failure rather than continuing: a partial bundle
// that reports success would be worse than an obvious stop.
if (code != 0) return code;
}
} finally {
manager.close();
}
return 0;
}