[tool] Refactor args of strings or YAML file lists (#8513)

Multiple commands in the Flutter plugin tool have arguments that accepts a list of strings or a list of YAML files that contain a list of strings. This introduces a `getYamlListArg` helper so that this logic doesn't need to be duplicated multiple times. 

In a subsequent pull requests, this will be used to add a list of packages that are allowed to have Xcode warnings. This will be used by the google_sign_in_ios package which will have warnings when using SwiftPM.

Part of: https://github.com/flutter/flutter/issues/146904
This commit is contained in:
Loïc Sharma
2025-01-28 16:48:29 -08:00
committed by GitHub
parent 2a4beb20c8
commit ef7e0d5076
8 changed files with 44 additions and 62 deletions

View File

@ -115,24 +115,8 @@ class PubspecCheckCommand extends PackageLoopingCommand {
}
}
// Load explicitly allowed packages.
_allowedUnpinnedPackages
.addAll(_getAllowedPackages(_allowDependenciesFlag));
_allowedPinnedPackages
.addAll(_getAllowedPackages(_allowPinnedDependenciesFlag));
}
Iterable<String> _getAllowedPackages(String flag) {
return getStringListArg(flag).expand<String>((String item) {
if (item.endsWith('.yaml')) {
final File file = packagesDir.fileSystem.file(item);
final Object? yaml = loadYaml(file.readAsStringSync());
if (yaml == null) {
return <String>[];
}
return (yaml as YamlList).toList().cast<String>();
}
return <String>[item];
});
_allowedUnpinnedPackages.addAll(getYamlListArg(_allowDependenciesFlag));
_allowedPinnedPackages.addAll(getYamlListArg(_allowPinnedDependenciesFlag));
}
@override