DpkConfig.parse constructor
DpkConfig.parse(
- ConfigReader reader
Implementation
factory DpkConfig.parse(ConfigReader reader) {
if (reader.has('dpk')) {
throw reader.error(
'The nested "dpk:" mapping is no longer supported. Move its keys to '
'the top level of the file.',
key: 'dpk',
);
}
reader.checkKeys([...keys, ...legacyKeys.keys], suggestions: keys);
_warnLegacy(reader, legacyKeys);
final modeName = reader.string('mode') ?? 'global';
final mode = DpkMode.values.where((m) => m.name == modeName).firstOrNull;
if (mode == null) {
throw reader.valueError(
'mode',
'"$modeName" is not a mode. Use "global" or "project".',
);
}
final scriptsReader = reader.child('scripts');
final scripts = scriptsReader == null
? const <String, Script>{}
: Script.parseAll(scriptsReader);
final catalogReader = reader.child('catalog');
final catalog = catalogReader == null ? null : Catalog.parse(catalogReader);
for (final child in [?scriptsReader, ?catalogReader]) {
reader.adoptWarnings(child);
}
return DpkConfig(
version: parseVersion(reader),
mode: mode,
sortPubspec:
reader.boolean('sort_pubspec') ??
reader.boolean('sortPubspec') ??
false,
workspace: reader.stringList('workspace'),
cacheDir: reader.string('cache_dir'),
patchDir: reader.string('patch_dir') ?? 'patches',
catalog: catalog,
scripts: scripts,
warnings: List.unmodifiable(reader.warnings),
);
}