//
//  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.description)
            Generate.exit(withError: error)
        }
        
        guard let configuration = try? YAMLDecoder().decode(ConfigurationFile.self, from: data) else {
            let error = GenerateError.invalidConfigurationFile(configurationFile)
            print(error.description)
            Generate.exit(withError: error)
        }
        
        return configuration
    }
}
