@@ -13,17 +13,19 @@ public class Env
13
13
{
14
14
public const string DEFAULT_ENVFILENAME = ".env" ;
15
15
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 )
18
17
{
19
18
return paths . Aggregate (
20
- additionalValues ? . ToArray ( ) ?? Array . Empty < KeyValuePair < string , string > > ( ) ,
19
+ Array . Empty < KeyValuePair < string , string > > ( ) ,
21
20
( kvps , path ) => kvps . Concat ( Load ( path , options , kvps ) ) . ToArray ( )
22
21
) ;
23
22
}
24
23
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 )
27
29
{
28
30
if ( options == null ) options = LoadOptions . DEFAULT ;
29
31
@@ -59,24 +61,27 @@ public static IEnumerable<KeyValuePair<string, string>> Load(string path = null,
59
61
return Enumerable . Empty < KeyValuePair < string , string > > ( ) ;
60
62
}
61
63
62
- return LoadContents ( File . ReadAllText ( path ) , options , additionalValues ) ;
64
+ return LoadContents ( File . ReadAllText ( path ) , options , previousValues ) ;
63
65
}
64
66
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 )
67
68
{
68
69
using ( var reader = new StreamReader ( file ) )
69
70
{
70
- return LoadContents ( reader . ReadToEnd ( ) , options , additionalValues ) ;
71
+ return LoadContents ( reader . ReadToEnd ( ) , options ) ;
71
72
}
72
73
}
73
74
74
75
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 )
76
81
{
77
82
if ( options == null ) options = LoadOptions . DEFAULT ;
78
83
79
- additionalValues = additionalValues ? . ToArray ( ) ?? Array . Empty < KeyValuePair < string , string > > ( ) ;
84
+ previousValues = previousValues ? . ToArray ( ) ?? Array . Empty < KeyValuePair < string , string > > ( ) ;
80
85
81
86
var envVarSnapshot = Environment . GetEnvironmentVariables ( ) . Cast < DictionaryEntry > ( )
82
87
. 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
87
92
: CreateDictionaryOption . TakeFirst ;
88
93
89
94
Parsers . EnvVarSnapshot =
90
- new ConcurrentDictionary < string , string > ( envVarSnapshot . Concat ( additionalValues )
95
+ new ConcurrentDictionary < string , string > ( envVarSnapshot . Concat ( previousValues )
91
96
. ToDotEnvDictionary ( dictionaryOption ) ) ;
92
97
93
98
var pairs = Parsers . ParseDotenvFile ( contents , options . ClobberExistingVars ) ;
94
99
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
96
101
var unClobberedPairs = ( options . ClobberExistingVars
97
102
? pairs
98
103
: pairs . Where ( p =>
99
- additionalValues . All ( pv => pv . Key != p . Key ) &&
104
+ previousValues . All ( pv => pv . Key != p . Key ) &&
100
105
Environment . GetEnvironmentVariable ( p . Key ) == null ) )
101
106
. ToArray ( ) ;
102
107
0 commit comments