import FileClient 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 { let fileUrl = FileManager.default .homeDirectoryForCurrentUser .appending(path: ".config") .appending(path: HPAKey.configDirName) .appending(path: HPAKey.defaultFileName) return .toml(fileUrl) } }