Caps-Train/Sources/ConfigurationFile.swift
Christoph Hagen f67a9a2de7 Improve CLI
2023-10-24 11:31:08 +02:00

37 lines
817 B
Swift

import Foundation
struct ConfigurationFile {
let folder: String?
let iterations: Int?
let server: String?
let authentication: String?
}
extension ConfigurationFile: Decodable {
}
extension ConfigurationFile {
init(at url: URL) throws {
guard FileManager.default.fileExists(atPath: url.path) else {
throw TrainingError.configurationFileMissing(url)
}
let data: Data
do {
data = try Data(contentsOf: url)
} catch {
throw TrainingError.configurationFileUnreadable(url, error)
}
do {
self = try JSONDecoder().decode(ConfigurationFile.self, from: data)
} catch {
throw TrainingError.configurationFileDecodingFailed(url, error)
}
}
}