feat: Breaking out more dependencies.

This commit is contained in:
2024-12-10 17:08:17 -05:00
parent 87390c4b63
commit 92cd6afa2b
20 changed files with 1408 additions and 691 deletions

View File

@@ -0,0 +1,53 @@
import Foundation
/// Represents a file location and type on disk for a configuration file.
public enum File: Equatable, Sendable {
case json(URL)
case toml(URL)
public init?(_ url: URL) {
if url.cleanFilePath.hasSuffix("json") {
self = .json(url)
} else if url.cleanFilePath.hasSuffix("toml") {
self = .toml(url)
} else {
return nil
}
}
public init?(_ path: String) {
self.init(URL(filePath: path))
}
public static func json(_ path: String) -> Self {
.json(URL(filePath: path))
}
public static func toml(_ path: String) -> Self {
.toml(URL(filePath: path))
}
public var url: URL {
switch self {
case let .json(url): return url
case let .toml(url): return url
}
}
public var path: String {
url.cleanFilePath
}
public static var `default`: Self {
.toml("~/.config/\(HPAKey.configDirName)/\(HPAKey.defaultFileName)")
}
}
@_spi(Internal)
public extension URL {
var cleanFilePath: String {
absoluteString.replacing("file://", with: "")
}
}