parse method
Parse the name
=value
value pair and report any errors to onError
. If
the option is a flag, value
will be null. Note, name
is commonly
unused. It is provided because SingleOptionParser
can be registered for
multiple option names in genericOptionsParser
.
Implementation
@override
void parse(String name, String? value, OnError onError) {
if (value == null) {
onError('Invalid $bazelOptionId option. Expected a non-empty value.');
return;
}
for (final entry in value.split(';')) {
final fields = entry.split('|');
if (fields.length != 3) {
onError(
'ERROR: expected package_name|input_root|output_root. Got: $entry');
continue;
}
final pkg = BazelPackage(fields[0], fields[1], fields[2]);
if (!output.containsKey(pkg.inputRoot)) {
output[pkg.inputRoot] = pkg;
} else {
final prev = output[pkg.inputRoot]!;
if (pkg.name != prev.name) {
onError('ERROR: multiple packages with input_root ${pkg.inputRoot}: '
'${prev.name} and ${pkg.name}');
continue;
}
if (pkg.outputRoot != prev.outputRoot) {
onError('ERROR: conflicting output_roots for package ${pkg.name}: '
'${prev.outputRoot} and ${pkg.outputRoot}');
continue;
}
}
}
}