Skip to content

Commit 17ed70d

Browse files
rename additionalValues to previousValues and hide them inside Env, making it just an implementationDetail for LoadMulti
1 parent f8b72b8 commit 17ed70d

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/DotNetEnv/Env.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ public class Env
1313
{
1414
public const string DEFAULT_ENVFILENAME = ".env";
1515

16-
public static IEnumerable<KeyValuePair<string, string>> LoadMulti(string[] paths, LoadOptions options = null,
17-
IEnumerable<KeyValuePair<string, string>> additionalValues = null)
16+
public static IEnumerable<KeyValuePair<string, string>> LoadMulti(string[] paths, LoadOptions options = null)
1817
{
1918
return paths.Aggregate(
20-
additionalValues?.ToArray() ?? Array.Empty<KeyValuePair<string, string>>(),
19+
Array.Empty<KeyValuePair<string, string>>(),
2120
(kvps, path) => kvps.Concat(Load(path, options, kvps)).ToArray()
2221
);
2322
}
2423

25-
public static IEnumerable<KeyValuePair<string, string>> Load(string path = null, LoadOptions options = null,
26-
IEnumerable<KeyValuePair<string, string>> additionalValues = null)
24+
public static IEnumerable<KeyValuePair<string, string>> Load(string path = null, LoadOptions options = null)
25+
=> Load(path, options, null);
26+
27+
private static IEnumerable<KeyValuePair<string, string>> Load(string path, LoadOptions options,
28+
IEnumerable<KeyValuePair<string, string>> previousValues)
2729
{
2830
if (options == null) options = LoadOptions.DEFAULT;
2931

@@ -59,24 +61,27 @@ public static IEnumerable<KeyValuePair<string, string>> Load(string path = null,
5961
return Enumerable.Empty<KeyValuePair<string, string>>();
6062
}
6163

62-
return LoadContents(File.ReadAllText(path), options, additionalValues);
64+
return LoadContents(File.ReadAllText(path), options, previousValues);
6365
}
6466

65-
public static IEnumerable<KeyValuePair<string, string>> Load(Stream file, LoadOptions options = null,
66-
IEnumerable<KeyValuePair<string, string>> additionalValues = null)
67+
public static IEnumerable<KeyValuePair<string, string>> Load(Stream file, LoadOptions options = null)
6768
{
6869
using (var reader = new StreamReader(file))
6970
{
70-
return LoadContents(reader.ReadToEnd(), options, additionalValues);
71+
return LoadContents(reader.ReadToEnd(), options);
7172
}
7273
}
7374

7475
public static IEnumerable<KeyValuePair<string, string>> LoadContents(string contents,
75-
LoadOptions options = null, IEnumerable<KeyValuePair<string, string>> additionalValues = null)
76+
LoadOptions options = null)
77+
=> LoadContents(contents, options, null);
78+
79+
private static IEnumerable<KeyValuePair<string, string>> LoadContents(string contents,
80+
LoadOptions options, IEnumerable<KeyValuePair<string, string>> previousValues)
7681
{
7782
if (options == null) options = LoadOptions.DEFAULT;
7883

79-
additionalValues = additionalValues?.ToArray() ?? Array.Empty<KeyValuePair<string, string>>();
84+
previousValues = previousValues?.ToArray() ?? Array.Empty<KeyValuePair<string, string>>();
8085

8186
var envVarSnapshot = Environment.GetEnvironmentVariables().Cast<DictionaryEntry>()
8287
.Select(entry => new KeyValuePair<string, string>(entry.Key.ToString(), entry.Value.ToString()))
@@ -87,16 +92,16 @@ public static IEnumerable<KeyValuePair<string, string>> LoadContents(string cont
8792
: CreateDictionaryOption.TakeFirst;
8893

8994
Parsers.EnvVarSnapshot =
90-
new ConcurrentDictionary<string, string>(envVarSnapshot.Concat(additionalValues)
95+
new ConcurrentDictionary<string, string>(envVarSnapshot.Concat(previousValues)
9196
.ToDotEnvDictionary(dictionaryOption));
9297

9398
var pairs = Parsers.ParseDotenvFile(contents, options.ClobberExistingVars);
9499

95-
// for NoClobber, remove pairs which are exactly contained in additionalValues or present in EnvironmentVariables
100+
// for NoClobber, remove pairs which are exactly contained in previousValues or present in EnvironmentVariables
96101
var unClobberedPairs = (options.ClobberExistingVars
97102
? pairs
98103
: pairs.Where(p =>
99-
additionalValues.All(pv => pv.Key != p.Key) &&
104+
previousValues.All(pv => pv.Key != p.Key) &&
100105
Environment.GetEnvironmentVariable(p.Key) == null))
101106
.ToArray();
102107

0 commit comments

Comments
 (0)