Repository: vapor/vapor
File: Sources/Vapor/Environment/Environment.swift (Swift)

Code before:

/// The environment the application is running in, i.e., production, dev, etc. All `Container`s will have
/// an `Environment` that can be used to dynamically register and configure services.
///
///     switch env {
///     case .production:
///         app.http.server.configuration = ...
///     default: break
///     }
///
/// The `Environment` can also be used to retrieve variables from the Process' ENV.
///
///     print(Environment.get("DB_PASSWORD"))
///
public struct Environment: Sendable, Equatable {
    // MARK: - Detection
    
    /// Detects the environment from `ConfigReader`. Parses the `vapor.env` flag.
    ///
    /// - Parameters:
    ///   - config: `ConfigReader` to parse `vapor.env` flag from.
    /// - Returns: The detected environment, or default env.
    public static func detect(from config: ConfigReader) throws -> Environment {
        config.string(forKey: "vapor.env", as: Environment.self, default: .development)
    }
    
    // MARK: - Presets

    /// An environment for deploying your application to consumers.
    public static var production: Environment { .init(name: "production") }

    /// An environment for developing your application.
    public static var development: Environment { .init(name: "development") }

    /// An environment for testing your application.
    public static var testing: Environment { .init(name: "testing") }

    /// Creates a custom environment.
    public static func custom(name: String) -> Environment { .init(name: name) }

    // MARK: - Env

    /// Gets a key from the process environment
    public static func get(_ key: String) -> String? {
        return ProcessInfo.processInfo.environment[key]
    }

    /// The current process of the environment.
    public static var process: Process {
        return Process()
    }

Review comment (suggestion):
We should clearly document the config keys somewhere, both for this PR and for users so we can align on them

Code after:

/// The environment the application is running in, i.e., production, dev, etc. All `Container`s will have
/// an `Environment` that can be used to dynamically register and configure services.
///
///     switch env {
///     case .production:
///         app.http.server.configuration = ...
///     default: break
///     }
///
/// The `Environment` can also be used to retrieve variables from the Process' ENV.
///
///     print(Environment.get("DB_PASSWORD"))
///
public struct Environment: Sendable, Equatable {
    // MARK: - Detection
    
    /// Detects the environment from `ConfigReader`. Parses the `vapor.env` flag.
    ///
    /// - Parameter config: `ConfigReader` to parse `vapor.env` flag from.
    /// - Returns: The detected environment, or default env.
    ///
    /// ## Configuration keys:
    /// - `vapor.env`: (string, optional, default: `.development`): The name of the environment to use.
    public static func detect(from config: ConfigReader) throws -> Environment {
        config.string(forKey: "vapor.env", as: Environment.self, default: .development)
    }
    
    // MARK: - Presets

    /// An environment for deploying your application to consumers.
    public static var production: Environment { .init(name: "production") }

    /// An environment for developing your application.
    public static var development: Environment { .init(name: "development") }

    /// An environment for testing your application.
    public static var testing: Environment { .init(name: "testing") }

    /// Creates a custom environment.
    public static func custom(name: String) -> Environment { .init(name: name) }

    // MARK: - Env

    /// Gets a key from the process environment
    public static func get(_ key: String) -> String? {
        return ProcessInfo.processInfo.environment[key]
    }

    /// The current process of the environment.
    public static var process: Process {