feat: Commit pre integrating configuration client into cli-client.
This commit is contained in:
@@ -47,7 +47,7 @@ public extension Configuration {
|
||||
struct Branch: Codable, Equatable, Sendable {
|
||||
|
||||
/// Include the commit sha in the output for this strategy.
|
||||
let includeCommitSha: Bool
|
||||
public let includeCommitSha: Bool
|
||||
|
||||
/// Create a new branch strategy.
|
||||
///
|
||||
@@ -217,10 +217,10 @@ public extension Configuration {
|
||||
struct VersionStrategy: Codable, Equatable, Sendable {
|
||||
|
||||
/// Set if we're using the branch and commit sha to derive the version.
|
||||
let branch: Branch?
|
||||
public let branch: Branch?
|
||||
|
||||
/// Set if we're using semvar to derive the version.
|
||||
let semvar: SemVar?
|
||||
public let semvar: SemVar?
|
||||
|
||||
/// Create a new version strategy that uses branch and commit sha to derive the version.
|
||||
///
|
||||
|
||||
@@ -17,13 +17,13 @@ public extension DependencyValues {
|
||||
public struct ConfigurationClient: Sendable {
|
||||
|
||||
/// Find a configuration file in the given directory or in current working directory.
|
||||
public var find: @Sendable (URL?) async throws -> ConfigruationFile?
|
||||
public var find: @Sendable (URL?) async throws -> ConfigurationFile?
|
||||
|
||||
/// Load a configuration file.
|
||||
public var load: @Sendable (ConfigruationFile) async throws -> Configuration
|
||||
public var load: @Sendable (ConfigurationFile) async throws -> Configuration
|
||||
|
||||
/// Write a configuration file.
|
||||
public var write: @Sendable (Configuration, ConfigruationFile) async throws -> Void
|
||||
public var write: @Sendable (Configuration, ConfigurationFile) async throws -> Void
|
||||
|
||||
/// Find a configuration file and load it if found.
|
||||
public func findAndLoad(_ url: URL? = nil) async throws -> Configuration {
|
||||
@@ -46,7 +46,7 @@ extension ConfigurationClient: DependencyKey {
|
||||
}
|
||||
}
|
||||
|
||||
private func findConfiguration(_ url: URL?) async throws -> ConfigruationFile? {
|
||||
private func findConfiguration(_ url: URL?) async throws -> ConfigurationFile? {
|
||||
@Dependency(\.fileClient) var fileClient
|
||||
|
||||
var url: URL! = url
|
||||
@@ -55,8 +55,10 @@ private func findConfiguration(_ url: URL?) async throws -> ConfigruationFile? {
|
||||
}
|
||||
|
||||
// Check if url is a valid configuration url.
|
||||
var configurationFile = ConfigruationFile(url: url)
|
||||
if let configurationFile { return configurationFile }
|
||||
var configurationFile = ConfigurationFile(url: url)
|
||||
if let configurationFile, fileClient.fileExists(configurationFile.url) {
|
||||
return configurationFile
|
||||
}
|
||||
|
||||
guard try await fileClient.isDirectory(url.cleanFilePath) else {
|
||||
throw ConfigurationClientError.invalidConfigurationDirectory(path: url.cleanFilePath)
|
||||
@@ -64,13 +66,17 @@ private func findConfiguration(_ url: URL?) async throws -> ConfigruationFile? {
|
||||
|
||||
// Check for toml file.
|
||||
let tomlUrl = url.appending(path: "\(ConfigurationClient.Constants.defaultFileNameWithoutExtension).toml")
|
||||
configurationFile = ConfigruationFile(url: tomlUrl)
|
||||
if let configurationFile { return configurationFile }
|
||||
configurationFile = ConfigurationFile(url: tomlUrl)
|
||||
if let configurationFile, fileClient.fileExists(configurationFile.url) {
|
||||
return configurationFile
|
||||
}
|
||||
|
||||
// Check for json file.
|
||||
let jsonUrl = url.appending(path: "\(ConfigurationClient.Constants.defaultFileNameWithoutExtension).json")
|
||||
configurationFile = ConfigruationFile(url: jsonUrl)
|
||||
if let configurationFile { return configurationFile }
|
||||
configurationFile = ConfigurationFile(url: jsonUrl)
|
||||
if let configurationFile, fileClient.fileExists(configurationFile.url) {
|
||||
return configurationFile
|
||||
}
|
||||
|
||||
// Couldn't find valid configuration file.
|
||||
return nil
|
||||
|
||||
@@ -3,7 +3,7 @@ import FileClient
|
||||
import Foundation
|
||||
|
||||
/// Represents a configuration file type and location.
|
||||
public enum ConfigruationFile: Equatable, Sendable {
|
||||
public enum ConfigurationFile: Equatable, Sendable {
|
||||
|
||||
/// A json configuration file.
|
||||
case json(URL)
|
||||
@@ -34,7 +34,7 @@ public enum ConfigruationFile: Equatable, Sendable {
|
||||
}
|
||||
|
||||
/// The url of the file.
|
||||
var url: URL {
|
||||
public var url: URL {
|
||||
switch self {
|
||||
case let .json(url): return url
|
||||
case let .toml(url): return url
|
||||
@@ -42,7 +42,7 @@ public enum ConfigruationFile: Equatable, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
extension ConfigruationFile {
|
||||
extension ConfigurationFile {
|
||||
|
||||
func load() async throws -> Configuration? {
|
||||
@Dependency(\.coders) var coders
|
||||
|
||||
Reference in New Issue
Block a user