load method

  1. @override
Map<String, dynamic> load({
  1. required bool shouldWarn,
})
override

Load the configurations.

Implementation

@override
Map<String, dynamic> load({required bool shouldWarn}) {
  final environment = <String, String>{};
  final searchDirectories = _searchDirectories(shouldWarn);

  for (final filename in files.toSet()) {
    for (final directory in searchDirectories) {
      try {
        final file = File(path.join(directory, filename));
        if (!file.existsSync()) continue;

        final lines = file.readAsLinesSync();
        final results = parser.parse(lines: lines, shouldWarn: shouldWarn);

        environment.addAll(results);

        if (skipMultipleLocations) break;
      } catch (e) {
        if (shouldWarn) {
          final message = switch (e) {
            InvalidLineError e =>
              'Invalid line in "${path.relative(path.join(directory, filename))}"'
                  'file: L${e.number} ${e.line}',
            _ => Error.safeToString(e),
          };

          warn(message);
        }

        continue;
      }
    }
  }

  return environment;
}