|
|
|
@ -8,24 +8,10 @@ import org.domaindrivenarchitecture.provs.syspec.domain.CommandSpec
|
|
|
|
|
import org.domaindrivenarchitecture.provs.syspec.domain.SpecConfig
|
|
|
|
|
import java.io.File
|
|
|
|
|
import java.io.FileWriter
|
|
|
|
|
import java.io.IOException
|
|
|
|
|
|
|
|
|
|
private const val DEFAULT_CONFIG_FILE = "syspec-config.yaml"
|
|
|
|
|
|
|
|
|
|
internal fun writeSpecConfigToFile(
|
|
|
|
|
fileName: String = DEFAULT_CONFIG_FILE,
|
|
|
|
|
config: SpecConfig
|
|
|
|
|
) {
|
|
|
|
|
FileWriter(fileName).use {
|
|
|
|
|
it.write(
|
|
|
|
|
Yaml.default.encodeToString(
|
|
|
|
|
SpecConfig.serializer(),
|
|
|
|
|
config
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------- read ----------------------------------
|
|
|
|
|
internal fun getSpecConfigFromFile(file: ConfigFileName? = null): SpecConfig {
|
|
|
|
|
val filename = file?.fileName ?: DEFAULT_CONFIG_FILE
|
|
|
|
|
|
|
|
|
@ -36,15 +22,8 @@ internal fun getSpecConfigFromFile(file: ConfigFileName? = null): SpecConfig {
|
|
|
|
|
return readFromFile(filename).yamlToType()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal fun findSpecConfigFromFile(file: ConfigFileName? = null): SpecConfig? {
|
|
|
|
|
return try {
|
|
|
|
|
val config = getSpecConfigFromFile(file)
|
|
|
|
|
config
|
|
|
|
|
} catch (e: IOException) {
|
|
|
|
|
println("Error: " + e.message)
|
|
|
|
|
null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
internal fun findSpecConfigFromFile(file: ConfigFileName? = null): Result<SpecConfig> = runCatching { getSpecConfigFromFile(file) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal fun getSpecConfigFromResource(resourcePath: String): SpecConfig {
|
|
|
|
|
val resource = Thread.currentThread().contextClassLoader.getResource(resourcePath)
|
|
|
|
@ -52,12 +31,20 @@ internal fun getSpecConfigFromResource(resourcePath: String): SpecConfig {
|
|
|
|
|
return resource.readText().yamlToType()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal fun findSpecConfigFromResource(resourcePath: String): SpecConfig? {
|
|
|
|
|
return try {
|
|
|
|
|
val config = getSpecConfigFromResource(resourcePath)
|
|
|
|
|
config
|
|
|
|
|
} catch (e: IllegalArgumentException) {
|
|
|
|
|
println("Error: " + e.message)
|
|
|
|
|
null
|
|
|
|
|
internal fun findSpecConfigFromResource(resourcePath: String): Result<SpecConfig> = runCatching { getSpecConfigFromResource(resourcePath) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------- write ----------------------------------
|
|
|
|
|
internal fun writeSpecConfigToFile(
|
|
|
|
|
fileName: String = DEFAULT_CONFIG_FILE,
|
|
|
|
|
config: SpecConfig
|
|
|
|
|
) {
|
|
|
|
|
FileWriter(fileName).use {
|
|
|
|
|
it.write(
|
|
|
|
|
Yaml.default.encodeToString(
|
|
|
|
|
SpecConfig.serializer(),
|
|
|
|
|
config
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|