From 78cf44074cfdf2667108bad00c4f121b479d3acf Mon Sep 17 00:00:00 2001 From: t4lz Date: Thu, 23 Nov 2023 13:46:38 +0100 Subject: [PATCH] show target selection dialog when there is no config (#199) --- changelog.d/198.fixed.md | 1 + .../main/kotlin/com/metalbear/mirrord/MirrordConfigAPI.kt | 1 + .../main/kotlin/com/metalbear/mirrord/MirrordExecManager.kt | 6 ++++-- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelog.d/198.fixed.md diff --git a/changelog.d/198.fixed.md b/changelog.d/198.fixed.md new file mode 100644 index 00000000..8cc0351b --- /dev/null +++ b/changelog.d/198.fixed.md @@ -0,0 +1 @@ +No target selection dialog was displayed when running without configuration. diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordConfigAPI.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordConfigAPI.kt index cf563049..2de67d9f 100644 --- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordConfigAPI.kt +++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordConfigAPI.kt @@ -30,6 +30,7 @@ class InvalidConfigException(path: String, reason: String) : MirrordError("faile * @throws InvalidConfigException if config cannot be found or parsed. */ fun isTargetSet(config: String?): Boolean { + config ?: return false val gson = Gson() // `path` will be either a normal string, or the string `"null"` due to `toString`. diff --git a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordExecManager.kt b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordExecManager.kt index 14627896..af7fbec0 100644 --- a/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordExecManager.kt +++ b/modules/core/src/main/kotlin/com/metalbear/mirrord/MirrordExecManager.kt @@ -114,7 +114,7 @@ class MirrordExecManager(private val service: MirrordProjectService) { // Find the mirrord config path, then call `mirrord verify-config {path}` so we can display warnings/errors // from the config without relying on mirrord-layer. val configPath = service.configApi.getConfigPath(mirrordConfigFromEnv) - MirrordLogger.logger.debug("MirrordExecManager.start: config path is $cli") + MirrordLogger.logger.debug("MirrordExecManager.start: config path is $configPath") val verifiedConfig = configPath?.let { val verifiedConfigOutput = @@ -131,7 +131,9 @@ class MirrordExecManager(private val service: MirrordProjectService) { MirrordLogger.logger.debug("Verified Config: $verifiedConfig, Target selection.") - val target = if (configPath != null && !isTargetSet(verifiedConfig?.config)) { + val targetSet = verifiedConfig?.let { isTargetSet(it.config) } ?: false + val target = if (!targetSet) { + // There is no config file or the config does not specify a target, so show dialog. MirrordLogger.logger.debug("target not selected, showing dialog") chooseTarget(cli, wslDistribution, configPath).also { if (it == MirrordExecDialog.targetlessTargetName) {