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 String? packageName = argResults?['package'] as String?;
final List<DartPackage> allPackages =
findAllPackages(SidekickContext.projectRoot);
if (packageName != null) {
final package =
allPackages.where((it) => it.name == packageName).firstOrNull;
if (package == null) {
throw "Package with name $packageName not found in "
"${SidekickContext.projectRoot.path}";
}
_warnIfNotInProject();
// only get deps for selected package
_getDependencies(package);
return;
}
_warnIfNotInProject();
final errorBuffer = StringBuffer();
final globExcludes = excludeGlob
.expand((rule) {
// start search at repo root
final root = SidekickContext.projectRoot.path;
return Glob("$root/$rule").listSync(root: root);
})
.whereType<Directory>()
.mapNotNull((e) => DartPackage.fromDirectory(e));
final excluded = [
...exclude,
...globExcludes,
// exclude the sidekick package, because it should load it's dependencies
// using the embedded sdk.
// Since this command is already running, the deps are already loaded.
DartPackage.fromDirectory(SidekickContext.sidekickPackage.root)!,
];
for (final package in allPackages.whereNot(excluded.contains)) {
try {
_getDependencies(package);
} catch (e, stack) {
print('Error while getting dependencies for ${package.name} '
'(${package.root.path})');
errorBuffer.writeln("${package.name}: $e\n$stack");
}
}
final errorText = errorBuffer.toString();
if (errorText.isNotEmpty) {
printerr("\n\nErrors while getting dependencies:");
printerr(errorText);
exitCode = 1;
}
}