load static method
Loads the configuration from the analysis_options.yaml file in the
provided root directory. Returns the default configuration if the file
does not exist or if the api_guard section is missing.
Implementation
static ApiGuardConfig load(Directory root) {
final configFile = File('${root.path}/analysis_options.yaml');
if (configFile.existsSync()) {
try {
return ApiGuardConfig.fromYaml(configFile);
} catch (e) {
// We can't use the logger here easily without creating a dependency
// loop or passing it in. It's safe to throw or print if needed,
// but for now let's just return default and maybe log outside.
// Actually, let's rethrow or let the caller handle.
// But to keep it simple as a helper:
logger.warn('Warning: Failed to load analysis_options.yaml: $e');
return ApiGuardConfig.defaultConfig();
}
}
return ApiGuardConfig.defaultConfig();
}