run method
Runs this command.
The return value is wrapped in a Future
if necessary and returned by
CommandRunner.runCommand
.
Implementation
@override
Future<bool> run() async {
bool result = true;
final inputPaths = args['input'].toString().split(',');
final outZipPath = args['output'].toString();
final ind = (args['indent'] ?? inRs).toString();
final zipName = path.basename(outZipPath);
try {
final zip = ZipFileEncoder()..create(outZipPath);
for (var inputPath in inputPaths) {
final baseName = path.basename(inputPath);
final isDir = FileSystemEntity.isDirectorySync(inputPath);
final closer =
logger.printFixed('📦 Packing $baseName → $zipName', ind);
if (isDir) {
zip.addDirectory(Directory(inputPath));
} else {
zip.addFile(File(inputPath));
}
result = closer(result);
}
zip.close();
} catch (e) {
logger.useMemo(e.toString());
result = false;
}
return result;
}