fromFile static method
Parses a configuration from a file.
It is expected that the caller ensures filePath:
- exists in the File System, otherwise throws ArgumentError
- extension is in {".json", ".yaml", ".yml"} (case-insensitive), otherwise throws UnsupportedError
Throws a FormatException if the file content is invalid.
Implementation
static ConfigurationSource fromFile(final String filePath) {
final lowercaseFilePath = filePath.toLowerCase();
if (lowercaseFilePath.endsWith('.json')) {
return fromString(
_loadFile(filePath),
format: ConfigEncoding.json,
);
}
if (lowercaseFilePath.endsWith('.yaml') ||
lowercaseFilePath.endsWith('.yml')) {
return fromString(
_loadFile(filePath),
format: ConfigEncoding.yaml,
);
}
throw UnsupportedError('Unsupported file extension: $filePath');
}