use default config file if no config was specified and default config file exists
This commit is contained in:
parent
aef96be7f3
commit
8323b84bbe
2 changed files with 14 additions and 6 deletions
|
@ -8,6 +8,8 @@ import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig
|
|||
import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance
|
||||
import org.domaindrivenarchitecture.provs.framework.core.cli.quit
|
||||
import java.io.FileNotFoundException
|
||||
import java.nio.file.Files
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
/**
|
||||
|
@ -21,22 +23,28 @@ fun main(args: Array<String>) {
|
|||
exitProcess(1)
|
||||
}
|
||||
|
||||
val config = if (cmd.configFile == null) DesktopConfig() else
|
||||
val defaultConfigFileName = "desktop-config.yaml"
|
||||
val config = if ((cmd.configFile == null) && !Files.isRegularFile(Path(defaultConfigFileName))) {
|
||||
println("ATTENTION: No config provided => using an empty config.")
|
||||
DesktopConfig()
|
||||
} else {
|
||||
val configFileName = cmd.configFile?.fileName ?: defaultConfigFileName
|
||||
try {
|
||||
getConfig(cmd.configFile.fileName)
|
||||
getConfig(configFileName)
|
||||
} catch (e: SerializationException) {
|
||||
println(
|
||||
"Error: File \"${cmd.configFile.fileName}\" has an invalid format and or invalid data."
|
||||
"Error: File \"${configFileName}\" has an invalid format and or invalid data."
|
||||
)
|
||||
null
|
||||
} catch (e: FileNotFoundException) {
|
||||
println(
|
||||
"Error: File\u001b[31m ${cmd.configFile.fileName} \u001b[0m was not found.\n" +
|
||||
"Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m ${cmd.configFile.fileName} \u001B[0m " +
|
||||
"Error: File\u001b[31m ${configFileName} \u001b[0m was not found.\n" +
|
||||
"Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m ${configFileName} \u001B[0m " +
|
||||
"and change the content according to your needs."
|
||||
)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
if (config == null) {
|
||||
println("No suitable config found.")
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.io.FileWriter
|
|||
* Returns DesktopConfig; data for config is read from specified file.
|
||||
* Throws exceptions FileNotFoundException, SerializationException if file is not found resp. cannot be parsed.
|
||||
*/
|
||||
fun getConfig(filename: String = "desktop-config.yaml"): DesktopConfig = readFromFile(filename).yamlToType()
|
||||
fun getConfig(filename: String): DesktopConfig = readFromFile(filename).yamlToType()
|
||||
|
||||
|
||||
@Suppress("unused")
|
||||
|
|
Loading…
Reference in a new issue