feat: Adds generate-config as json file.

This commit is contained in:
2024-11-29 22:25:50 -05:00
parent 505f7d8013
commit ed3f752694
6 changed files with 97 additions and 36 deletions

View File

@@ -18,6 +18,7 @@ public struct FileClient: Sendable {
public var homeDir: @Sendable () -> URL = { URL(string: "~/")! }
public var isDirectory: @Sendable (URL) -> Bool = { _ in false }
public var isReadable: @Sendable (URL) -> Bool = { _ in false }
public var fileExists: @Sendable (String) -> Bool = { _ in false }
public var write: @Sendable (String, Data) throws -> Void
}
@@ -33,6 +34,7 @@ extension FileClient: DependencyKey {
homeDir: { client.homeDir },
isDirectory: { client.isDirectory(url: $0) },
isReadable: { client.isReadable(url: $0) },
fileExists: { client.fileExists(at: $0) },
write: { path, data in
try data.write(to: URL(filePath: path))
}
@@ -66,6 +68,10 @@ private struct LiveFileClient: @unchecked Sendable {
try fileManager.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
}
func fileExists(at path: String) -> Bool {
fileManager.fileExists(atPath: path)
}
func loadFile(at url: URL, into env: inout [String: String], decoder: JSONDecoder) throws {
@Dependency(\.logger) var logger
logger.trace("Begin load file for: \(path(for: url))")