Config.load constructor

Config.load(
  1. String path
)

Implementation

factory Config.load(String path) {
  final file = fs.file(path);

  if (!file.existsSync()) {
    log('Config file not found at $path');
    return Config();
  }

  final content = file.readAsStringSync();

  final yaml =
      jsonDecode(jsonEncode(loadYaml(content))) as Map<String, dynamic>;

  final exclude = switch (yaml['exclude']) {
    final String string => [string],
    final List<dynamic> list => list.map((e) => '$e').toList(),
    _ => [],
  };

  final format = switch (yaml['format']) {
    final bool v => v,
    'true' => true,
    'false' => false,
    _ => false,
  };

  return Config(exclude: exclude as List<String>, format: format);
}