doRun method
Implementation
@override
Future<int> doRun() async {
final args = argResults!;
var dependency = _getDepName(args[_argDependency] as String?);
if (dependency == null) {
printInfo('Enter package name to update:');
dependency = _getDepName(console.readLineSync());
if (dependency == null) {
return error(1,
message: 'Nothing to update - dependency name is not provider. '
'You can pass package name as '
'--$_argDependency=PACKAGE_NAME or '
'-${_argDependencyAbbr}PACKAGE_NAME');
}
}
printInfo('Updating <$dependency>...');
final pubspecFiles = await getPubspecs();
if (pubspecFiles.isNotEmpty) {
printVerbose('Sort pubspec files consider mutual dependencies');
_sortPubspecs(pubspecFiles);
printVerbose('Update pubspec files');
var updated = 0;
for (final file in pubspecFiles) {
if (await _updatePubspec(file, dependency)) {
printInfo('Dependency updated for ${file.path}');
updated++;
}
}
if (updated == 0) {
return error(1,
message:
'Dependency <$dependency> is not found in any of pubspec files.');
} else {
printInfo('Updated $updated pubspec files.');
}
}
return success(message: 'Bye 👋');
}