configParserBuilder method

Future<ConfigParser?> configParserBuilder()

Implementation

Future<ConfigParser?> configParserBuilder() async {
  final configParser = await ConfigParser.distributeYaml(
    argResults?['config'] as String? ?? 'distribution.yaml',
    globalResults!,
  );
  if (operationKey.isNotEmpty) {
    if (operationKey.contains(".")) {
      final key = operationKey.split('.');
      configParser.tasks.removeWhere((task) => task.key != key[0]);
      if (key.isNotEmpty) {
        for (var task in configParser.tasks) {
          task.jobs.removeWhere((job) => job.key != key[1]);
        }
        if (configParser.tasks.every((task) => task.jobs.isEmpty)) {
          logger.logError(
            "No jobs found for the specified operation key: $operationKey",
          );
          return null;
        }
      }
    } else {
      configParser.tasks.removeWhere((task) => task.key != operationKey);
    }

    if (configParser.tasks.isEmpty) {
      logger.logError("No task found with the key: $operationKey");
      return null;
    }
  }

  return configParser;
}