postProcessDockerPs function
Post-process for docker ps-style output (JSON lines with .Names, .Image).
Implementation
List<FigSuggestion> postProcessDockerPs(String out, [List<String>? tokens]) {
return out
.split('\n')
.where((line) => line.trim().isNotEmpty)
.map((line) {
try {
final parsedJSON = Map<String, String>.from((jsonDecode(line) as Map)
.map((k, v) => MapEntry(k.toString(), v?.toString() ?? '')));
return FigSuggestion(
name: parsedJSON['Names'],
displayName: '${parsedJSON['Names']} (${parsedJSON['Image']})',
icon: 'fig://icon?type=docker',
);
} catch (_) {
return null;
}
})
.whereType<FigSuggestion>()
.toList();
}