Initial commit
This commit is contained in:
38
Sources/GitVersion/Client.swift
Normal file
38
Sources/GitVersion/Client.swift
Normal file
@@ -0,0 +1,38 @@
|
||||
import Foundation
|
||||
#if canImport(FoundationNetworking)
|
||||
import FoundationNetworking
|
||||
#endif
|
||||
import ShellClient
|
||||
import XCTestDynamicOverlay
|
||||
|
||||
public struct GitVersionClient {
|
||||
private var currentVersion: (String?) throws -> String
|
||||
|
||||
public init(currentVersion: @escaping (String?) throws -> String) {
|
||||
self.currentVersion = currentVersion
|
||||
}
|
||||
|
||||
public func currentVersion(in gitDirectory: String? = nil) throws -> String {
|
||||
try self.currentVersion(gitDirectory)
|
||||
}
|
||||
|
||||
public mutating func override(with version: String) {
|
||||
self.currentVersion = { _ in version }
|
||||
}
|
||||
}
|
||||
|
||||
extension GitVersionClient: TestDependencyKey {
|
||||
|
||||
public static let testValue = GitVersionClient(
|
||||
currentVersion: unimplemented("\(Self.self).currentVersion", placeholder: "")
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
extension DependencyValues {
|
||||
|
||||
public var gitVersionClient: GitVersionClient {
|
||||
get { self[GitVersionClient.self] }
|
||||
set { self[GitVersionClient.self] = newValue }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user