servicesGenerator top-level property

FigGenerator servicesGenerator
final

服务生成器(带有 postProcess)

Implementation

final FigGenerator servicesGenerator = FigGenerator(
  script: (context) {
    try {
      final compose = getComposeCommand(context);
      final fileArgs = extractFileArgs(context);
      return [...compose, ...fileArgs, 'config', '--services'];
    } catch (e) {
      // 如果出现错误,返回空命令或默认命令
      print('Error building compose command: $e');
      return ['docker-compose', 'config', '--services'];
    }
  },
  splitOn: '\n',
  postProcess: (String out, [List<String>? tokens]) {
    // 可选的后处理函数,用于进一步处理输出
    return out
        .split('\n')
        .where((service) => service.trim().isNotEmpty)
        .map((service) => FigSuggestion(
              name: service.trim(),
              description: 'Docker Compose service',
              icon: '🐳',
            ))
        .toList();
  },
);