readToolsScopeFile function
Reads the tools: section of the yaml file at path through env.
Returns (null, null) when the file or the section is absent,
(null, message) when the file/section is broken, else the parsed
config.
Implementation
Future<(ToolsConfig?, String?)> readToolsScopeFile(
ExecutionEnv env,
String path,
) async {
final text = (await env.readTextFile(path)).valueOrNull;
if (text == null || text.trim().isEmpty) return (null, null);
final Object? doc;
try {
doc = loadYaml(text);
} on Object catch (error) {
return (null, 'cannot parse $path: $error');
}
if (doc is! YamlMap) return (null, 'cannot parse $path: not a yaml map');
final node = doc['tools'];
if (node == null) return (const ToolsConfig(), null);
try {
return (ToolsConfig.fromYaml(node), null);
} on ConfigException catch (error) {
return (null, 'invalid tools section in $path: ${error.message}');
}
}