sharedPostProcess function

List<FigSuggestion> sharedPostProcess(
  1. String out, [
  2. List<String>? tokens
])

Shared post-process for list commands (JSON lines with .Name, .ID).

Implementation

List<FigSuggestion> sharedPostProcess(String out, [List<String>? tokens]) {
  return out
      .split('\n')
      .where((line) => line.trim().isNotEmpty)
      .map((line) {
        try {
          final i = jsonDecode(line) as Map<String, dynamic>;
          final name = i['Name']?.toString();
          final id = i['ID']?.toString();
          if (name == null) return null;
          return FigSuggestion(
            name: name,
            description: id,
            icon: 'fig://icon?type=docker',
          );
        } catch (_) {
          return null;
        }
      })
      .whereType<FigSuggestion>()
      .toList();
}