Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
Reviewed-on: #1
28 lines
825 B
Swift
28 lines
825 B
Swift
//
|
|
// ConfigurationFileParser.swift
|
|
//
|
|
//
|
|
// Created by Thibaut Schmitt on 30/08/2022.
|
|
//
|
|
|
|
import Foundation
|
|
import Yams
|
|
|
|
class ConfigurationFileParser {
|
|
static func parse(_ configurationFile: String) -> ConfigurationFile {
|
|
guard let data = FileManager().contents(atPath: configurationFile) else {
|
|
let error = GenerateError.fileNotExists(configurationFile)
|
|
print(error.localizedDescription)
|
|
Generate.exit(withError: error)
|
|
}
|
|
|
|
guard let configuration = try? YAMLDecoder().decode(ConfigurationFile.self, from: data) else {
|
|
let error = GenerateError.invalidConfigurationFile(configurationFile)
|
|
print(error.localizedDescription)
|
|
Generate.exit(withError: error)
|
|
}
|
|
|
|
return configuration
|
|
}
|
|
}
|