parseConfigFile<T> function

Future<T> parseConfigFile<T>(
  1. dynamic file,
  2. Serializer<T> serializer
)

Implementation

Future<T> parseConfigFile<T>(
    /* String | File */ file, Serializer<T> serializer) async {
  File yaml;
  if (file is String) {
    yaml = File(file);
  } else if (file is File) {
    yaml = file;
  } else {
    throw ArgumentError.value(file, 'file', 'Should be file name or file');
  }
  if (!await yaml.exists()) {
    throw Exception("Config file ${yaml.path} not found!");
  }
  Map<String, dynamic> settings;
  try {
    settings =
        (loadYaml(await yaml.readAsString()) as Map).cast<String, dynamic>();
  } catch (e) {
    throw Exception("Config file is not a valid yaml file: $e");
  }
  return serializer.fromMap(settings);
}