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

Commit

Permalink
Merge pull request #20 from vapor/env-cli
Browse files Browse the repository at this point in the history
store cli arguments on environment
  • Loading branch information
tanner0101 committed Mar 25, 2018
2 parents d2b233b + df54f3d commit 02205a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 6 additions & 3 deletions Sources/Service/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ public struct Environment {
/// `true` if this environment is production.
public let isRelease: Bool

/// Create a new environment.
/// Use the static helper methods.
internal init(name: String, isRelease: Bool) {
/// The command-line arguments for this `Environment`.
public var arguments: [String]

/// Create a new environment. Use the static helper methods.
public init(name: String, isRelease: Bool, arguments: [String] = CommandLine.arguments) {
self.name = name
self.isRelease = isRelease
self.arguments = arguments
}
}

Expand Down
12 changes: 11 additions & 1 deletion Sources/Service/Provider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public protocol Provider {
/// The location of the views directory
/// _relative_ to the root of the provider package.
static var viewsDir: String { get }

/// Gives the provider a chance to detect information from the `Environment`.
/// - parameters:
/// - env: Mutable `Environment`. This can be used to parse command line flags, fetch env variables, and more.
func detect(_ env: inout Environment) throws

/// Register all services provided by the provider here.
func register(_ services: inout Services) throws
Expand All @@ -49,11 +54,16 @@ extension Provider {
// MARK: Optional

extension Provider {
/// By default, the `Public` folder will be used as all `Provider`'s public dir.
public static var publicDir: String {
return "Public"
}


/// By default, the `Resources/Views` folder will be used for all `Provider`'s views dir.
public static var viewsDir: String {
return "Resources/Views"
}

/// By default, all providers will ignore the `Environment` during `detect(_:)`.
public func detect(_ env: inout Environment) throws { }
}

0 comments on commit 02205a1

Please sign in to comment.