@@ -55,20 +55,46 @@ void main(List<String> args) {
55
55
..addFlag ('help' ,
56
56
abbr: 'h' ,
57
57
negatable: false ,
58
- help: 'Print usage and exit' );
58
+ help: 'Print usage and exit' )
59
+ ..addMultiOption ('ignored-class-name' ,
60
+ help: 'The name of a class whose containing constant instances that '
61
+ 'should not be retained. This is useful in situations--such as '
62
+ 'the web--where unused constants are not tree shaken from dill '
63
+ 'files.\n\n Note: each provided class name must pair with an '
64
+ 'invocation of "--ignored-class-library-uri" and appear in the '
65
+ 'same order.' ,
66
+ valueHelp: 'Icons' )
67
+ ..addMultiOption ('ignored-class-library-uri' ,
68
+ help: 'The package: URI of a class to ignore.\n\n Note: each provided '
69
+ 'class name must pair with an invocation of '
70
+ '"--ignored-class-name" and appear in the same order.' ,
71
+ valueHelp: 'package:flutter/src/material/icons.dart' );
59
72
60
73
final ArgResults argResults = parser.parse (args);
61
- T getArg <T >(String name) => argResults[name] as T ;
74
+ T getArg <T >(String name) {
75
+ try {
76
+ return argResults[name] as T ;
77
+ } catch (err) {
78
+ stderr.writeln ('Parsing error trying to parse the argument "$name "' );
79
+ rethrow ;
80
+ }
81
+ }
62
82
63
83
if (getArg <bool >('help' )) {
64
84
stdout.writeln (parser.usage);
65
85
exit (0 );
66
86
}
67
87
88
+ final List <List <String >> ignoredClasses = _pairIgnoredClassNamesAndUris (
89
+ getArg <Object ?>('ignored-class-name' ),
90
+ getArg <Object ?>('ignored-class-library-uri' ),
91
+ );
92
+
68
93
final ConstFinder finder = ConstFinder (
69
94
kernelFilePath: getArg <String >('kernel-file' ),
70
95
classLibraryUri: getArg <String >('class-library-uri' ),
71
96
className: getArg <String >('class-name' ),
97
+ ignoredClasses: ignoredClasses,
72
98
);
73
99
74
100
final JsonEncoder encoder = getArg <bool >('pretty' )
@@ -77,3 +103,38 @@ void main(List<String> args) {
77
103
78
104
stdout.writeln (encoder.convert (finder.findInstances ()));
79
105
}
106
+
107
+ List <List <String >> _pairIgnoredClassNamesAndUris (Object ? names, Object ? uris) {
108
+ // If the user provided neither option then we will not ignore any classes.
109
+ if (names == null && uris == null ) {
110
+ return const < List <String >> [];
111
+ }
112
+ // If the user provided one of the options but not the other, than this is a
113
+ // error!
114
+ if (names == null || uris == null ) {
115
+ stderr.writeln (
116
+ 'To ignore specific classes, both "--ignored-class-name" AND '
117
+ '"--ignored-class-library-uri" must be provided in order to uniquely '
118
+ 'identify the class.' ,
119
+ );
120
+ exit (1 );
121
+ }
122
+
123
+ names = names as List <String >;
124
+ uris = uris as List <String >;
125
+ final List <List <String >> pairs = < List <String >> [];
126
+
127
+ if (names.length != uris.length) {
128
+ stderr.writeln (
129
+ '"--ignored-class-name" was provided ${names .length } time(s) but '
130
+ '"--ignored-class-library-uri" was provided ${uris .length } time(s). '
131
+ 'Each ignored class name must be paired with exactly one ignored class '
132
+ 'library uri, provided in the same order.' ,
133
+ );
134
+ exit (1 );
135
+ }
136
+ for (int i = 0 ; i < names.length; i++ ) {
137
+ pairs.add (< String > [uris[i], names[i]]);
138
+ }
139
+ return pairs;
140
+ }
0 commit comments