@@ -77,7 +77,7 @@ abstract class PackageCommand extends Command<void> {
7777 argParser.addMultiOption (
7878 _excludeArg,
7979 abbr: 'e' ,
80- help: 'A list of packages to exclude from from this command.\n\n '
80+ help: 'A list of packages to exclude from this command.\n\n '
8181 'Alternately, a list of one or more YAML files that contain a list '
8282 'of packages to exclude.' ,
8383 defaultsTo: < String > [],
@@ -252,6 +252,22 @@ abstract class PackageCommand extends Command<void> {
252252 return List <String >.from (argResults! [key] as List <String >? ?? < String > []);
253253 }
254254
255+ /// Convenience accessor for arguments containing a list of strings and/or
256+ /// YAML files containing lists of strings.
257+ Set <String > getYamlListArg (String key) {
258+ return getStringListArg (key).expand <String >((String item) {
259+ if (item.endsWith ('.yaml' )) {
260+ final File file = packagesDir.fileSystem.file (item);
261+ final Object ? yaml = loadYaml (file.readAsStringSync ());
262+ if (yaml == null ) {
263+ return const < String > [];
264+ }
265+ return (yaml as YamlList ).toList ().cast <String >();
266+ }
267+ return < String > [item];
268+ }).toSet ();
269+ }
270+
255271 /// If true, commands should log timing information that might be useful in
256272 /// analyzing their runtime (e.g., the per-package time for multi-package
257273 /// commands).
@@ -277,25 +293,10 @@ abstract class PackageCommand extends Command<void> {
277293 _shardCount = shardCount;
278294 }
279295
280- /// Converts a list of items which are either package names or yaml files
281- /// containing a list of package names to a flat list of package names by
282- /// reading all the file contents.
283- Set <String > _expandYamlInPackageList (List <String > items) {
284- return items.expand <String >((String item) {
285- if (item.endsWith ('.yaml' )) {
286- final File file = packagesDir.fileSystem.file (item);
287- return (loadYaml (file.readAsStringSync ()) as YamlList )
288- .toList ()
289- .cast <String >();
290- }
291- return < String > [item];
292- }).toSet ();
293- }
294-
295296 /// Returns the set of packages to exclude based on the `--exclude` argument.
296297 Set <String > getExcludedPackageNames () {
297- final Set <String > excludedPackages = _excludedPackages ??
298- _expandYamlInPackageList ( getStringListArg ( _excludeArg) );
298+ final Set <String > excludedPackages =
299+ _excludedPackages ?? getYamlListArg ( _excludeArg);
299300 // Cache for future calls.
300301 _excludedPackages = excludedPackages;
301302 return excludedPackages;
@@ -460,9 +461,8 @@ abstract class PackageCommand extends Command<void> {
460461
461462 final Set <String > excludedPackageNames = getExcludedPackageNames ();
462463 final bool hasFilter = argResults? .wasParsed (_filterPackagesArg) ?? false ;
463- final Set <String >? excludeAllButPackageNames = hasFilter
464- ? _expandYamlInPackageList (getStringListArg (_filterPackagesArg))
465- : null ;
464+ final Set <String >? excludeAllButPackageNames =
465+ hasFilter ? getYamlListArg (_filterPackagesArg) : null ;
466466 if (excludeAllButPackageNames != null &&
467467 excludeAllButPackageNames.isNotEmpty) {
468468 final List <String > sortedList = excludeAllButPackageNames.toList ()
0 commit comments