@@ -144,7 +144,18 @@ public struct EnvironmentVariablesProvider: Sendable {
144144 var arrayDecoder : EnvironmentValueArrayDecoder
145145
146146 /// A decoder of bool values from a string
147- let boolDecoder : BoolDecoder
147+ static func decodeBool( from string: String ) -> Bool ? {
148+ let stringLowercased = string. lowercased ( )
149+ return if [ " true " , " false " ] . contains ( stringLowercased) {
150+ stringLowercased == " true "
151+ } else if [ " yes " , " no " ] . contains ( stringLowercased) {
152+ stringLowercased == " yes "
153+ } else if [ " 1 " , " 0 " ] . contains ( stringLowercased) {
154+ stringLowercased == " 1 "
155+ } else {
156+ nil
157+ }
158+ }
148159 }
149160
150161 /// The underlying snapshot of the provider.
@@ -173,14 +184,12 @@ public struct EnvironmentVariablesProvider: Sendable {
173184 public init (
174185 secretsSpecifier: SecretsSpecifier < String , String > = . none,
175186 bytesDecoder: some ConfigBytesFromStringDecoder = . base64,
176- boolDecoder: BoolDecoder = . init( ) ,
177187 arraySeparator: Character = " , "
178188 ) {
179189 self . init (
180190 environmentVariables: ProcessInfo . processInfo. environment,
181191 secretsSpecifier: secretsSpecifier,
182192 bytesDecoder: bytesDecoder,
183- boolDecoder: boolDecoder,
184193 arraySeparator: arraySeparator
185194 )
186195 }
@@ -212,7 +221,6 @@ public struct EnvironmentVariablesProvider: Sendable {
212221 environmentVariables: [ String : String ] ,
213222 secretsSpecifier: SecretsSpecifier < String , String > = . none,
214223 bytesDecoder: some ConfigBytesFromStringDecoder = . base64,
215- boolDecoder: BoolDecoder = . init( ) ,
216224 arraySeparator: Character = " , "
217225 ) {
218226 let tuples : [ ( String , EnvironmentValue ) ] = environmentVariables. map { key, value in
@@ -227,8 +235,7 @@ public struct EnvironmentVariablesProvider: Sendable {
227235 self . _snapshot = . init(
228236 environmentVariables: Dictionary ( uniqueKeysWithValues: tuples) ,
229237 bytesDecoder: bytesDecoder,
230- arrayDecoder: EnvironmentValueArrayDecoder ( separator: arraySeparator) ,
231- boolDecoder: boolDecoder
238+ arrayDecoder: EnvironmentValueArrayDecoder ( separator: arraySeparator)
232239 )
233240 }
234241
@@ -262,7 +269,6 @@ public struct EnvironmentVariablesProvider: Sendable {
262269 allowMissing: Bool = false ,
263270 secretsSpecifier: SecretsSpecifier < String , String > = . none,
264271 bytesDecoder: some ConfigBytesFromStringDecoder = . base64,
265- boolDecoder: BoolDecoder = . init( ) ,
266272 arraySeparator: Character = " , "
267273 ) async throws {
268274 try await self . init (
@@ -271,7 +277,6 @@ public struct EnvironmentVariablesProvider: Sendable {
271277 fileSystem: LocalCommonProviderFileSystem ( ) ,
272278 secretsSpecifier: secretsSpecifier,
273279 bytesDecoder: bytesDecoder,
274- boolDecoder: boolDecoder,
275280 arraySeparator: arraySeparator
276281 )
277282 }
@@ -294,7 +299,6 @@ public struct EnvironmentVariablesProvider: Sendable {
294299 fileSystem: some CommonProviderFileSystem ,
295300 secretsSpecifier: SecretsSpecifier < String , String > = . none,
296301 bytesDecoder: some ConfigBytesFromStringDecoder = . base64,
297- boolDecoder: BoolDecoder = . init( ) ,
298302 arraySeparator: Character = " , "
299303 ) async throws {
300304 let loadedData = try await fileSystem. fileContents ( atPath: environmentFilePath)
@@ -311,7 +315,6 @@ public struct EnvironmentVariablesProvider: Sendable {
311315 environmentVariables: EnvironmentFileParser . parsed ( contents) ,
312316 secretsSpecifier: secretsSpecifier,
313317 bytesDecoder: bytesDecoder,
314- boolDecoder: boolDecoder,
315318 arraySeparator: arraySeparator
316319 )
317320 }
@@ -408,7 +411,7 @@ extension EnvironmentVariablesProvider.Snapshot {
408411 }
409412 content = . double( doubleValue)
410413 case . bool:
411- guard let boolValue = boolDecoder . decodeBool ( from: stringValue) else {
414+ guard let boolValue = Self . decodeBool ( from: stringValue) else {
412415 try throwMismatch ( )
413416 }
414417 content = . bool( boolValue)
@@ -441,7 +444,7 @@ extension EnvironmentVariablesProvider.Snapshot {
441444 case . boolArray:
442445 let arrayValue = arrayDecoder. decode ( stringValue)
443446 let boolArray = try arrayValue. map { stringValue in
444- guard let boolValue = boolDecoder . decodeBool ( from: stringValue) else {
447+ guard let boolValue = Self . decodeBool ( from: stringValue) else {
445448 try throwMismatch ( )
446449 }
447450 return boolValue
0 commit comments