getMultilineValueFromLines function
Reads a YAML list value for key out of lines, e.g. the route_paths: block in sg_cli.yaml.
Collects every line that follows $key: until the list ends, plus an
inline value if the list starts on the same line as the key. Returns
null if key isn't found or has no values.
Implementation
List<String>? getMultilineValueFromLines({
required List<String> lines,
required String key,
}) {
final values = <String>[];
bool collecting = false;
for (var line in lines) {
if (collecting) {
values.add(line.trim());
}
if (line.startsWith('$key:')) {
collecting = true;
// handle single-line case like: key: value
var inlineValue = line.split(':').skip(1).join(':').trim();
if (inlineValue.isNotEmpty) {
values.add(inlineValue);
}
}
}
return values.isEmpty ? null : values;
}