Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Can't use custom environments when isRelease is true #32

Closed
rausnitz opened this issue Feb 5, 2019 · 2 comments
Closed

Can't use custom environments when isRelease is true #32

rausnitz opened this issue Feb 5, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@rausnitz
Copy link
Sponsor

rausnitz commented Feb 5, 2019

As far as I can tell there's no way to use a custom Environment where isRelease is true.

Here's a custom Environment example:

extension Environment {
    static var yesRelease: Environment {
        return .init(name: "yesRelease", isRelease: true)
    }
}

I've created the yesRelease environment but I can't seem to use it. When I run vapor run --env=yesRelease, the environment that gets created will always have isRelease set to false. https://github.com/vapor/console/blob/master/Sources/Command/Run/CommandInput.swift#L179

Then if I try to see whether the Environment equals my custom Environment, it will fail, because two environments must share the same name and isRelease properties in order to be equal. https://github.com/vapor/service/blob/master/Sources/Service/Environment/Environment.swift#L46

/// Called after your application has initialized.
public func boot(_ app: Application) throws {
    if app.environment == .yesRelease {
        // this won't get run
    }
}

I thought I made a mistake in my code when the app's Environment didn't match my custom Environment. If there's no way to use a custom Environment where isRelease is true, it shouldn't be possible to create one.

@rausnitz rausnitz changed the title Custom environments can't set isRelease to true Can't use custom environments when isRelease is true Feb 5, 2019
@tanner0101 tanner0101 transferred this issue from vapor/console-kit Feb 6, 2019
@tanner0101
Copy link
Member

Moving this issue to vapor/service since that's where Environment lives.

Yeah this is a problem with the current design.

I think going forward it would make more sense for Environment.isRelease to be an easy way to check if the app has been compiled with -c release or not. Right now there are checks for both Environment.isRelease and _isDebugAssertConfiguration in different places, leading to subtle differences in behavior.

The other option is to split --env into --envName and --envIsRelease or come up with some format like --env yesRelease:true for specifying isRelease.

@tanner0101 tanner0101 added the enhancement New feature or request label Feb 12, 2019
@tanner0101
Copy link
Member

Environment.isRelease now returns true when the program has been compiled with optimizations (-c release). See #29. This change will come with ServiceKit 2.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants