load method

DepSherpaConfig load({
  1. String? configPath,
  2. required String projectRoot,
})

Loads configuration for projectRoot, optionally overriding the path.

Implementation

DepSherpaConfig load({String? configPath, required String projectRoot}) {
  final String resolvedPath =
      configPath ?? p.join(projectRoot, 'dep_sherpa.yaml');
  if (!_fs.fileExists(resolvedPath)) {
    return DepSherpaConfig.defaults();
  }

  final Object? parsed = loadYaml(_fs.readFile(resolvedPath));
  if (parsed is! YamlMap) {
    throw const FormatException('dep_sherpa.yaml must contain a YAML map.');
  }

  final DepSherpaConfig defaults = DepSherpaConfig.defaults();
  return DepSherpaConfig(
    riskWeights: _riskWeights(parsed['risk_weights'], defaults.riskWeights),
    attenuation: _attenuation(parsed['attenuation'], defaults.attenuation),
    thresholds:
        _thresholds(parsed['hard_risk_thresholds'], defaults.thresholds),
    network: _network(parsed['network'], defaults.network),
    project: _project(parsed['project'], defaults.project),
    parameters: _parameters(parsed['parameters'], defaults.parameters),
    manualTrust: _manualTrust(parsed['manual_trust']),
  );
}