updateYamlValue method

Future<void> updateYamlValue(
  1. File yamlFile,
  2. List<Object> path,
  3. Object newValue
)

Safely updates a value in a YAML file using YamlEditor. This preserves comments and formatting.

Implementation

Future<void> updateYamlValue(
    File yamlFile, List<Object> path, Object newValue) async {
  if (!yamlFile.existsSync()) return;

  final content = await yamlFile.readAsString();
  final editor = YamlEditor(content);

  try {
    editor.update(path, newValue);
    await yamlFile.writeAsString(editor.toString());
  } catch (e) {
    // If path doesn't exist, we might need to use 'set' logic depending on requirements
    print('Could not update YAML path ${path.join('.')}: $e');
  }
}