diff --git a/.spi.yml b/.spi.yml new file mode 100644 index 0000000..4eff433 --- /dev/null +++ b/.spi.yml @@ -0,0 +1,4 @@ +version: 1 +builder: + configs: + - documentation_targets: [EnvironmentDecoder] \ No newline at end of file diff --git a/.swiftlint.yml b/.swiftlint.yml index d2cccba..6aff9ef 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -3,7 +3,7 @@ disabled_rules: - file_length opt_in_rules: -# - missing_docs + - missing_docs included: diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..7e82091 --- /dev/null +++ b/Package.resolved @@ -0,0 +1,24 @@ +{ + "originHash" : "f9dd70f40d8a36ca304b84a45f9f357e57d2c0708ffe79b8bb090797742b8601", + "pins" : [ + { + "identity" : "swift-docc-plugin", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-docc-plugin", + "state" : { + "revision" : "26ac5758409154cc448d7ab82389c520fa8a8247", + "version" : "1.3.0" + } + }, + { + "identity" : "swift-docc-symbolkit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-docc-symbolkit", + "state" : { + "revision" : "b45d1f2ed151d057b54504d653e0da5552844e34", + "version" : "1.0.0" + } + } + ], + "version" : 3 +} diff --git a/Package.swift b/Package.swift index 34df325..bd812be 100644 --- a/Package.swift +++ b/Package.swift @@ -9,6 +9,9 @@ let package = Package( name: "EnvironmentDecoder", targets: ["EnvironmentDecoder"]), ], + dependencies: [ + .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), + ], targets: [ .target( name: "EnvironmentDecoder"), diff --git a/Sources/EnvironmentDecoder/EnvironmentDecoder.swift b/Sources/EnvironmentDecoder/EnvironmentDecoder.swift index 43ae6de..bbb460a 100644 --- a/Sources/EnvironmentDecoder/EnvironmentDecoder.swift +++ b/Sources/EnvironmentDecoder/EnvironmentDecoder.swift @@ -1,8 +1,17 @@ import Foundation +/// `EnvironmentDecoder` facilitates the decoding of environment variables into semantic `Decodable` types. public final class EnvironmentDecoder { + /// Initializes `self` with default configuration. public init() {} + /// Decodes a top-level value of the given type from the given environment representation. + /// - Parameters: + /// - type: The type of the value to decode. + /// - environment: The environment dictionary to decode from, defaults to `ProcessInfo.processInfo.environment` + /// - Returns: A value of the requested type. + /// - Throws: `DecodingError` if an error occurs during decoding + /// - Throws: An error if any value throws an error during decoding public func decode(_ type: T.Type, from environment: [String: String] = ProcessInfo.processInfo.environment) throws -> T { let decoder = EnvironmentDecoderImpl(environment: environment, codingPathNode: .root) return try type.init(from: decoder)