|
|
|
@ -5,24 +5,24 @@ import org.domaindrivenarchitecture.provs.framework.core.readFromFile
|
|
|
|
|
import org.domaindrivenarchitecture.provs.framework.core.toYaml
|
|
|
|
|
import org.domaindrivenarchitecture.provs.framework.core.yamlToType
|
|
|
|
|
import org.domaindrivenarchitecture.provs.syspec.domain.CommandSpec
|
|
|
|
|
import org.domaindrivenarchitecture.provs.syspec.domain.SpecConfig
|
|
|
|
|
import org.domaindrivenarchitecture.provs.syspec.domain.SyspecConfig
|
|
|
|
|
import java.io.File
|
|
|
|
|
import java.io.FileWriter
|
|
|
|
|
|
|
|
|
|
private const val DEFAULT_CONFIG_FILE = "syspec-config.yaml"
|
|
|
|
|
|
|
|
|
|
// --------------------------------- read ----------------------------------
|
|
|
|
|
internal fun findSpecConfigFromFile(file: ConfigFileName? = null): Result<SpecConfig> = runCatching {
|
|
|
|
|
internal fun findSpecConfigFromFile(file: ConfigFileName? = null): Result<SyspecConfig> = runCatching {
|
|
|
|
|
val filePath = file?.fileName ?: DEFAULT_CONFIG_FILE
|
|
|
|
|
if ((filePath == DEFAULT_CONFIG_FILE) && !File(filePath).exists()) {
|
|
|
|
|
// provide default config
|
|
|
|
|
writeSpecConfigToFile(filePath, SpecConfig(listOf(CommandSpec("echo just_for_demo", "just_for_demo"))))
|
|
|
|
|
writeSpecConfigToFile(filePath, SyspecConfig(listOf(CommandSpec("echo just_for_demo", "just_for_demo"))))
|
|
|
|
|
}
|
|
|
|
|
readFromFile(filePath).yamlToType<SpecConfig>()
|
|
|
|
|
readFromFile(filePath).yamlToType<SyspecConfig>()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal fun findSpecConfigFromResource(resourcePath: String): Result<SpecConfig> = runCatching {
|
|
|
|
|
internal fun findSpecConfigFromResource(resourcePath: String): Result<SyspecConfig> = runCatching {
|
|
|
|
|
val resource = Thread.currentThread().contextClassLoader.getResource(resourcePath)
|
|
|
|
|
requireNotNull(resource) { "Resource $resourcePath not found" }
|
|
|
|
|
resource.readText().yamlToType()
|
|
|
|
@ -30,5 +30,5 @@ internal fun findSpecConfigFromResource(resourcePath: String): Result<SpecConfig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------- write ----------------------------------
|
|
|
|
|
internal fun writeSpecConfigToFile(fileName: String = DEFAULT_CONFIG_FILE, config: SpecConfig) =
|
|
|
|
|
internal fun writeSpecConfigToFile(fileName: String = DEFAULT_CONFIG_FILE, config: SyspecConfig) =
|
|
|
|
|
FileWriter(fileName).use { it.write(config.toYaml()) }
|