feat: Moves playbook run into playbook client, need to move tests.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import CommandClient
|
||||
import ConfigurationClient
|
||||
import Dependencies
|
||||
import DependenciesMacros
|
||||
@@ -17,6 +18,7 @@ public extension DependencyValues {
|
||||
@DependencyClient
|
||||
public struct PlaybookClient: Sendable {
|
||||
public var repository: Repository
|
||||
public var run: RunPlaybook
|
||||
}
|
||||
|
||||
public extension PlaybookClient {
|
||||
@@ -33,23 +35,131 @@ public extension PlaybookClient {
|
||||
public func directory() async throws -> String {
|
||||
try await directory(nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static var liveValue: Self {
|
||||
.init {
|
||||
try await installPlaybook(configuration: $0)
|
||||
} directory: {
|
||||
try await findDirectory(configuration: $0)
|
||||
public extension PlaybookClient {
|
||||
|
||||
@DependencyClient
|
||||
struct RunPlaybook: Sendable {
|
||||
public var buildProject: @Sendable (BuildOptions) async throws -> Void
|
||||
public var createProject: @Sendable (CreateOptions) async throws -> Void
|
||||
|
||||
public struct SharedRunOptions: Equatable, Sendable {
|
||||
public let extraOptions: [String]?
|
||||
public let inventoryFilePath: String?
|
||||
public let loggingOptions: LoggingOptions
|
||||
public let quiet: Bool
|
||||
public let shell: String?
|
||||
|
||||
public init(
|
||||
extraOptions: [String]?,
|
||||
inventoryFilePath: String?,
|
||||
loggingOptions: LoggingOptions,
|
||||
quiet: Bool,
|
||||
shell: String?
|
||||
) {
|
||||
self.extraOptions = extraOptions
|
||||
self.inventoryFilePath = inventoryFilePath
|
||||
self.loggingOptions = loggingOptions
|
||||
self.quiet = quiet
|
||||
self.shell = shell
|
||||
}
|
||||
}
|
||||
|
||||
@dynamicMemberLookup
|
||||
public struct BuildOptions: Equatable, Sendable {
|
||||
public let projectDirectory: String?
|
||||
public let shared: SharedRunOptions
|
||||
|
||||
public init(
|
||||
extraOptions: [String]?,
|
||||
inventoryFilePath: String?,
|
||||
loggingOptions: LoggingOptions,
|
||||
quiet: Bool,
|
||||
shell: String?,
|
||||
projectDirectory: String
|
||||
) {
|
||||
self.projectDirectory = projectDirectory
|
||||
self.shared = .init(
|
||||
extraOptions: extraOptions,
|
||||
inventoryFilePath: inventoryFilePath,
|
||||
loggingOptions: loggingOptions,
|
||||
quiet: quiet,
|
||||
shell: shell
|
||||
)
|
||||
}
|
||||
|
||||
public subscript<T>(dynamicMember keyPath: KeyPath<SharedRunOptions, T>) -> T {
|
||||
shared[keyPath: keyPath]
|
||||
}
|
||||
}
|
||||
|
||||
@dynamicMemberLookup
|
||||
public struct CreateOptions: Equatable, Sendable {
|
||||
public let projectDirectory: String
|
||||
public let shared: SharedRunOptions
|
||||
public let template: Configuration.Template
|
||||
public let useLocalTemplateDirectory: Bool
|
||||
|
||||
public init(
|
||||
extraOptions: [String]?,
|
||||
inventoryFilePath: String?,
|
||||
loggingOptions: LoggingOptions,
|
||||
projectDirectory: String,
|
||||
quiet: Bool,
|
||||
shell: String?,
|
||||
template: Configuration.Template,
|
||||
useLocalTemplateDirectory: Bool
|
||||
) {
|
||||
self.projectDirectory = projectDirectory
|
||||
self.template = template
|
||||
self.useLocalTemplateDirectory = useLocalTemplateDirectory
|
||||
self.shared = .init(
|
||||
extraOptions: extraOptions,
|
||||
inventoryFilePath: inventoryFilePath,
|
||||
loggingOptions: loggingOptions,
|
||||
quiet: quiet,
|
||||
shell: shell
|
||||
)
|
||||
}
|
||||
|
||||
public subscript<T>(dynamicMember keyPath: KeyPath<SharedRunOptions, T>) -> T {
|
||||
shared[keyPath: keyPath]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension PlaybookClient: DependencyKey {
|
||||
public static let testValue: PlaybookClient = Self(repository: Repository())
|
||||
extension PlaybookClient.Repository: DependencyKey {
|
||||
public static var liveValue: Self {
|
||||
.init {
|
||||
try await installPlaybook(configuration: $0)
|
||||
} directory: {
|
||||
try await findDirectory(configuration: $0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static var liveValue: PlaybookClient {
|
||||
extension PlaybookClient.RunPlaybook: DependencyKey {
|
||||
public static var liveValue: PlaybookClient.RunPlaybook {
|
||||
.init(
|
||||
repository: .liveValue
|
||||
buildProject: { try await $0.run() },
|
||||
createProject: { try await $0.run() }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension PlaybookClient: DependencyKey {
|
||||
public static let testValue: PlaybookClient = Self(
|
||||
repository: Repository(),
|
||||
run: RunPlaybook()
|
||||
)
|
||||
|
||||
public static var liveValue: PlaybookClient {
|
||||
.init(
|
||||
repository: .liveValue,
|
||||
run: .liveValue
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user