Files
swift-hpa/Sources/PlaybookClient/PlaybookClient.swift

56 lines
1.2 KiB
Swift

import ConfigurationClient
import Dependencies
import DependenciesMacros
import FileClient
import Foundation
import ShellClient
// TODO: Add update checks and pull for the playbook.
public extension DependencyValues {
var playbookClient: PlaybookClient {
get { self[PlaybookClient.self] }
set { self[PlaybookClient.self] = newValue }
}
}
@DependencyClient
public struct PlaybookClient: Sendable {
public var repository: Repository
}
public extension PlaybookClient {
@DependencyClient
struct Repository: Sendable {
public var install: @Sendable (Configuration?) async throws -> Void
public var directory: @Sendable (Configuration?) async throws -> String
public func install() async throws {
try await install(nil)
}
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)
}
}
}
}
extension PlaybookClient: DependencyKey {
public static let testValue: PlaybookClient = Self(repository: Repository())
public static var liveValue: PlaybookClient {
.init(
repository: .liveValue
)
}
}