mirror of
https://github.com/flutter/packages.git
synced 2025-08-06 17:28:42 +08:00
[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:
@ -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
|
||||
|
Reference in New Issue
Block a user