load static method
Implementation
static Future<Config> load([String? configPath]) async {
// Default to assetx.yaml in current directory
configPath ??= 'assetx.yaml';
final file = File(configPath);
if (!await file.exists()) {
throw FileSystemException('Configuration file not found: $configPath');
}
final content = await file.readAsString();
final yamlDoc = loadYaml(content);
if (yamlDoc == null) {
return Config([]);
}
// Handle both direct list format and entries key format
List<dynamic> entriesData;
if (yamlDoc is List) {
entriesData = yamlDoc;
} else if (yamlDoc is Map && yamlDoc['entries'] != null) {
entriesData = yamlDoc['entries'];
} else {
throw FormatException('Invalid configuration format');
}
final entries = entriesData
.map((entry) => ConfigEntry.fromYaml(Map<String, dynamic>.from(entry)))
.toList();
return Config(entries);
}