feat: Adding documentation comments.
All checks were successful
CI / Run Tests (push) Successful in 2m28s

This commit is contained in:
2024-12-17 13:32:05 -05:00
parent f8e89ed0fa
commit 54c07886ad
8 changed files with 245 additions and 68 deletions

View File

@@ -38,7 +38,7 @@ public struct ConfigurationClient: Sendable {
/// ## NOTE: This uses the `fileClient.write` under the hood, so if you need to control
/// what happens during tests, then you can customize the behavior of the fileClient.
///
var write: @Sendable (File, Configuration, Bool) async throws -> Void
public var write: @Sendable (WriteOptions) async throws -> Void
/// Find the user's configuration and load it.
public func findAndLoad() async throws -> Configuration {
@@ -62,13 +62,19 @@ public struct ConfigurationClient: Sendable {
to file: File,
force: Bool = false
) async throws {
try await write(file, configuration, force)
try await write(.init(configuration, to: file, force: force))
}
/// Represents the options to generate a configuration file for a user.
public struct GenerateOptions: Equatable, Sendable {
/// Force generation, overwritting existing file if it exists.
public let force: Bool
/// Generate a `json` file instead of the default `toml` file.
public let json: Bool
/// The path to generate a file in.
public let path: Path?
public init(
@@ -81,11 +87,39 @@ public struct ConfigurationClient: Sendable {
self.path = path
}
/// Represents the path option for generating a configuration file for a user.
///
/// This can either be a full file path or a directory. If a directory is supplied
/// then we will use the default file name of 'config' and add the extension dependning
/// on if the caller wants a `json` or `toml` file.
public enum Path: Equatable, Sendable {
case file(File)
case directory(String)
}
}
/// Represents the options required to write a configuration file.
public struct WriteOptions: Equatable, Sendable {
/// The configuration to wrtie to the file path.
public let configuration: Configuration
/// The file path to write the configuration to.
public let file: File
/// Force overwritting an existing file, if it exists.
public let force: Bool
public init(
_ configuration: Configuration,
to file: File,
force: Bool
) {
self.configuration = configuration
self.file = file
self.force = force
}
}
}
extension ConfigurationClient: DependencyKey {
@@ -97,7 +131,7 @@ extension ConfigurationClient: DependencyKey {
find: { try await liveClient.find() },
generate: { try await liveClient.generate($0) },
load: { try await liveClient.load(file: $0) },
write: { try await liveClient.write($1, to: $0, force: $2) }
write: { try await liveClient.write($0) }
)
}
@@ -225,7 +259,7 @@ struct LiveConfigurationClient {
} else {
// Json does not allow comments, so we write the mock configuration
// to the file path.
try await write(.mock, to: File(fileUrl)!, force: options.force)
try await write(.init(.mock, to: File(fileUrl)!, force: options.force))
}
return fileUrl.cleanFilePath
@@ -247,10 +281,12 @@ struct LiveConfigurationClient {
}
func write(
_ configuration: Configuration,
to file: File,
force: Bool
_ options: ConfigurationClient.WriteOptions
) async throws {
let configuration = options.configuration
let file = options.file
let force = options.force
let exists = fileManager.fileExists(file.url)
if !force, exists {