From 8cc3c9d89004bfb4efc76a5227eda93a7a2b4c7b Mon Sep 17 00:00:00 2001 From: pgreze Date: Tue, 7 Mar 2023 17:35:34 +0900 Subject: [PATCH] Solve idea resolution when toolbox is not installed --- .../kotlin/com/github/pgreze/aidea/app/App.kt | 2 +- .../github/pgreze/aidea/app/ChooseInstall.kt | 2 +- .../github/pgreze/aidea/app/OpenMainKts.kt | 31 +++++++++---------- .../com/github/pgreze/aidea/idea/Idea.kt | 5 --- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/app/src/main/kotlin/com/github/pgreze/aidea/app/App.kt b/app/src/main/kotlin/com/github/pgreze/aidea/app/App.kt index 26ca057..a392138 100644 --- a/app/src/main/kotlin/com/github/pgreze/aidea/app/App.kt +++ b/app/src/main/kotlin/com/github/pgreze/aidea/app/App.kt @@ -20,7 +20,7 @@ fun main(args: Array) { class App : CliktCommand( help = """ - idea alternative supporting a multi-installation setup + IntelliJ provided idea shell script alternative supporting a multi-installation setup (like Jetbrains Toolbox but in your shell). Without any argument, displays all the found installations. diff --git a/app/src/main/kotlin/com/github/pgreze/aidea/app/ChooseInstall.kt b/app/src/main/kotlin/com/github/pgreze/aidea/app/ChooseInstall.kt index 947b5de..0ca8bcc 100644 --- a/app/src/main/kotlin/com/github/pgreze/aidea/app/ChooseInstall.kt +++ b/app/src/main/kotlin/com/github/pgreze/aidea/app/ChooseInstall.kt @@ -21,7 +21,7 @@ private fun List.displayChoiceHeaders() { private fun selectInstallIndex(size: Int): Int? { while (true) { print("Which installation to use? ") - return (readLine() ?: return null) // ctrl+d + return (readlnOrNull() ?: return null) // ctrl+d .toIntOrNull() ?.takeIf { it - 1 in 0 until size } ?: continue diff --git a/app/src/main/kotlin/com/github/pgreze/aidea/app/OpenMainKts.kt b/app/src/main/kotlin/com/github/pgreze/aidea/app/OpenMainKts.kt index 96a1e83..5b65e59 100644 --- a/app/src/main/kotlin/com/github/pgreze/aidea/app/OpenMainKts.kt +++ b/app/src/main/kotlin/com/github/pgreze/aidea/app/OpenMainKts.kt @@ -15,13 +15,13 @@ fun File.generateMainKtsProject(): File = resolveMainKtsProject() .apply { require(deleteRecursively()) { - throw IOException("Could not delete $this") + throw IOException("Could not delete everything in $this") } mkdirs() - resolve("build.gradle.kts") - .writeText(BUILD_GRADLE_KTS) - resolve("settings.gradle") - .writeText("rootProject.name = \"${name}\"") + + resolve("build.gradle.kts").writeText(BUILD_GRADLE_KTS) + + resolve("settings.gradle").writeText("rootProject.name = \"${name}\"") resolve("src").let { srcDir -> srcDir.mkdir() @@ -30,16 +30,15 @@ fun File.generateMainKtsProject(): File = } } -private val BUILD_GRADLE_KTS = """ - plugins { - kotlin("jvm") version "1.7.10" - } +private const val BUILD_GRADLE_KTS = """plugins { + kotlin("jvm") version "1.7.10" +} - repositories { - mavenCentral { content { includeGroupByRegex("org.jetbrains(|.kotlin)") } } - } +repositories { + mavenCentral { content { includeGroupByRegex("org.jetbrains(|.kotlin)") } } +} - dependencies { - implementation(kotlin("stdlib-jdk8")) - } -""".trimIndent() +dependencies { + implementation(kotlin("stdlib-jdk8")) +} +""" diff --git a/idea/src/main/kotlin/com/github/pgreze/aidea/idea/Idea.kt b/idea/src/main/kotlin/com/github/pgreze/aidea/idea/Idea.kt index 7346a0b..419b7eb 100644 --- a/idea/src/main/kotlin/com/github/pgreze/aidea/idea/Idea.kt +++ b/idea/src/main/kotlin/com/github/pgreze/aidea/idea/Idea.kt @@ -54,11 +54,6 @@ fun listIdeaInstallations(): Sequence = sequence { private fun File.resolveToolboxLaunchers( ideaType: IdeaType ): Sequence = sequence { - if (isDirectory.not()) { - throw IllegalArgumentException("Invalid toolbox directory $this") - } - - // TODO: improve this part listFiles()?.forEach f1@{ f1 -> // ch-0 if (f1.isDirectory.not()) return@f1 f1.listFiles()?.forEach f2@{ f2 -> // 202.7660.26