updateYamlValue method
Safely updates a value in a YAML file using YamlEditor. Preserves comments and formatting.
Implementation
Future<void> updateYamlValue(
File yamlFile, List<Object> path, Object newValue) async {
if (!yamlFile.existsSync()) {
Logger.warning(
'Cannot update YAML: File not found at "${yamlFile.path}"');
return;
}
try {
final content = await yamlFile.readAsString();
final editor = YamlEditor(content);
editor.update(path, newValue);
await yamlFile.writeAsString(editor.toString());
} catch (e) {
Logger.warning(
'Could not update YAML path "${path.join('.')}" in "${yamlFile.path}": $e',
);
}
}