diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/Application.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/Application.kt index 86f3de3..b08f513 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/Application.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/Application.kt @@ -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) { 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.") diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DesktopConfigRepository.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DesktopConfigRepository.kt index efaf236..b35ee88 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DesktopConfigRepository.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DesktopConfigRepository.kt @@ -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")