Skip to content

Commit f14e948

Browse files
committed
Replace kotlinx.cli with Clikt and make stuff suspending.
1 parent d9affdb commit f14e948

26 files changed

+348
-313
lines changed

build.gradle.kts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
}
1010

1111
group = "co.touchlab"
12-
version = "2.1.0"
12+
version = "2.2.0"
1313

1414
kotlin {
1515
listOf(macosX64(), macosArm64()).forEach {
@@ -31,9 +31,9 @@ kotlin {
3131
sourceSets {
3232
val commonMain by getting {
3333
dependencies {
34-
implementation(libs.kotlinx.cli)
34+
implementation(libs.clikt)
35+
implementation(libs.mordant)
3536
implementation(libs.kotlinx.serialization.json)
36-
implementation(libs.kermit)
3737
implementation(libs.kotlinx.coroutines.core)
3838
}
3939
}
@@ -63,7 +63,6 @@ kotlin {
6363
}
6464

6565
all {
66-
languageSettings.optIn("kotlinx.cli.ExperimentalCli")
6766
languageSettings.optIn("kotlinx.cinterop.BetaInteropApi")
6867
languageSettings.optIn("kotlin.experimental.ExperimentalNativeApi")
6968
}

gradle/libs.versions.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
[versions]
2-
kotlin = "2.0.0"
2+
kotlin = "2.1.10"
33
kotlinx-coroutines = "1.7.3"
4-
kotlinx-cli = "0.3.6"
54
kotlinx-serialization = "1.6.0"
65
kermit = "1.2.2"
76
gradle-doctor = "0.9.2"
7+
clikt = "5.0.3"
8+
mordant = "3.0.1"
89

910
[libraries]
1011
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
11-
kotlinx-cli = { module = "org.jetbrains.kotlinx:kotlinx-cli", version.ref = "kotlinx-cli" }
1212
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
1313
kermit = { module = "co.touchlab:kermit", version.ref = "kermit" }
14+
clikt = { module = "com.github.ajalt.clikt:clikt", version.ref = "clikt" }
15+
mordant = { module = "com.github.ajalt.mordant:mordant", version.ref = "mordant" }
1416

1517
[plugins]
1618
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/macosMain/kotlin/co/touchlab/xcode/cli/EchoWriter.kt

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
package co.touchlab.xcode.cli
22

3-
import co.touchlab.kermit.Logger
4-
import co.touchlab.xcode.cli.command.Install
53
import co.touchlab.xcode.cli.util.Console
64

75
object InstallationFacade {
8-
private val logger = Logger.withTag("InstallationFacade")
9-
10-
fun installAll(xcodeInstallations: List<XcodeHelper.XcodeInstallation>, fixXcode15: Boolean) {
6+
suspend fun installAll(xcodeInstallations: List<XcodeHelper.XcodeInstallation>, fixXcode15: Boolean) {
117
XcodeHelper.ensureXcodeNotRunning()
128

139
val bundledVersion = PluginManager.bundledVersion
14-
logger.v { "Bundled plugin version = $bundledVersion" }
10+
Console.muted("Bundled plugin version = $bundledVersion")
1511
val installedVersion = PluginManager.installedVersion
16-
logger.v { "Installed plugin version = ${installedVersion ?: "N/A"}" }
12+
Console.muted("Installed plugin version = ${installedVersion ?: "N/A"}")
1713

1814
if (installedVersion != null) {
1915
val (confirmation, notification) = when {
2016
bundledVersion > installedVersion -> {
21-
"Do you want to update from $installedVersion to $bundledVersion? y/n: " to "Updating to $bundledVersion"
17+
"Do you want to update from $installedVersion to $bundledVersion?" to "Updating to $bundledVersion"
2218
}
2319
bundledVersion == installedVersion -> {
24-
"Do you want to reinstall version $installedVersion? y/n: " to "Reinstalling $installedVersion"
20+
"Do you want to reinstall version $installedVersion?" to "Reinstalling $installedVersion"
2521
}
2622
bundledVersion < installedVersion -> {
27-
"Do you want to downgrade from $installedVersion to $bundledVersion? y/n: " to "Downgrading to $bundledVersion"
23+
"Do you want to downgrade from $installedVersion to $bundledVersion?" to "Downgrading to $bundledVersion"
2824
}
2925
else -> error("Unhandled comparison possibility!")
3026
}
@@ -33,11 +29,11 @@ object InstallationFacade {
3329
return
3430
}
3531

36-
logger.v { "Installation confirmed." }
37-
logger.i { notification }
32+
Console.muted("Installation confirmed.")
33+
Console.info(notification)
3834
uninstallAll()
3935
} else {
40-
logger.i { "Installing $bundledVersion." }
36+
Console.info("Installing $bundledVersion.")
4137
}
4238

4339
PluginManager.install()
@@ -50,36 +46,36 @@ object InstallationFacade {
5046
LLDBInitManager.install()
5147
PluginManager.enable(bundledVersion, xcodeInstallations)
5248

53-
logger.i { "Installation complete." }
49+
Console.info("Installation complete.")
5450
}
5551

56-
fun enable(xcodeInstallations: List<XcodeHelper.XcodeInstallation>) {
52+
suspend fun enable(xcodeInstallations: List<XcodeHelper.XcodeInstallation>) {
5753
XcodeHelper.ensureXcodeNotRunning()
5854

5955
val installedVersion = PluginManager.installedVersion ?: run {
60-
Console.echo("Plugin not installed, nothing to enable.")
56+
Console.warning("Plugin not installed, nothing to enable.")
6157
return
6258
}
6359

6460
PluginManager.enable(installedVersion, xcodeInstallations)
6561

66-
logger.i { "Plugin enabled." }
62+
Console.info("Plugin enabled.")
6763
}
6864

69-
fun disable(xcodeInstallations: List<XcodeHelper.XcodeInstallation>) {
65+
suspend fun disable(xcodeInstallations: List<XcodeHelper.XcodeInstallation>) {
7066
XcodeHelper.ensureXcodeNotRunning()
7167

7268
val installedVersion = PluginManager.installedVersion ?: run {
73-
Console.echo("Plugin not installed, nothing to disable.")
69+
Console.warning("Plugin not installed, nothing to disable.")
7470
return
7571
}
7672

7773
PluginManager.disable(installedVersion, xcodeInstallations)
7874

79-
logger.i { "Plugin disabled." }
75+
Console.info("Plugin disabled.")
8076
}
8177

82-
fun fixXcode15(xcodeInstallations: List<XcodeHelper.XcodeInstallation>) {
78+
suspend fun fixXcode15(xcodeInstallations: List<XcodeHelper.XcodeInstallation>) {
8379
XcodeHelper.ensureXcodeNotRunning()
8480

8581
val installedVersion = PluginManager.installedVersion
@@ -95,14 +91,14 @@ object InstallationFacade {
9591
}
9692
}
9793

98-
logger.i { "Xcode 15 fix applied." }
94+
Console.info("Xcode 15 fix applied.")
9995
}
10096

101-
fun sync(xcodeInstallations: List<XcodeHelper.XcodeInstallation>, fixXcode15: Boolean) {
97+
suspend fun sync(xcodeInstallations: List<XcodeHelper.XcodeInstallation>, fixXcode15: Boolean) {
10298
XcodeHelper.ensureXcodeNotRunning()
10399

104100
val installedVersion = PluginManager.installedVersion ?: run {
105-
Console.echo("Plugin not installed, nothing to synchronize.")
101+
Console.warning("Plugin not installed, nothing to synchronize.")
106102
return
107103
}
108104

@@ -113,16 +109,16 @@ object InstallationFacade {
113109
}
114110
PluginManager.enable(installedVersion, xcodeInstallations)
115111

116-
logger.i { "Synchronization complete." }
112+
Console.info("Synchronization complete.")
117113
}
118114

119-
fun uninstallAll() {
120-
logger.v { "Will uninstall all plugin components." }
115+
suspend fun uninstallAll() {
116+
Console.muted("Will uninstall all plugin components.")
121117
XcodeHelper.ensureXcodeNotRunning()
122118
PluginManager.uninstall()
123119
LangSpecManager.uninstall()
124120
LLDBInitManager.uninstall()
125121

126-
logger.i { "Uninstallation complete." }
122+
Console.info("Uninstallation complete.")
127123
}
128124
}

src/macosMain/kotlin/co/touchlab/xcode/cli/LLDBInitManager.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package co.touchlab.xcode.cli
22

3-
import co.touchlab.kermit.Logger
43
import co.touchlab.xcode.cli.util.Console
54
import co.touchlab.xcode.cli.util.File
65
import co.touchlab.xcode.cli.util.Path
@@ -15,7 +14,6 @@ object LLDBInitManager {
1514
private val sourceMainLlvmInit = "command source ~/.lldbinit"
1615
private val lldbInitFile = File(Path.home / ".lldbinit")
1716
private val lldbInitXcodeFile = File(Path.home / ".lldbinit-Xcode")
18-
private val logger = Logger.withTag("LLDBInitManager")
1917

2018
val isInstalled: Boolean
2119
get() {
@@ -38,16 +36,16 @@ object LLDBInitManager {
3836

3937
val oldContents = when {
4038
lldbInitXcodeFile.exists() -> {
41-
logger.v { "${lldbInitXcodeFile.path} exists, will append LLDB init into it." }
39+
Console.muted("${lldbInitXcodeFile.path} exists, will append LLDB init into it.")
4240
lldbInitXcodeFile.stringContents().kt
4341
}
4442
lldbInitFile.exists() -> {
4543
Console.echo("""
4644
This installer will create a new file at '~/.lldbinit-Xcode'. This file takes precedence over the '~/.lldbinit' file.
4745
To keep using configuration from '~/.lldbinit' file, it needs to be sourced by the newly created '~/.lldbinit-Xcode' file.
4846
""".trimIndent())
49-
if (Console.confirm("Do you want to source the '~/.lldbinit' file? y/n: ")) {
50-
logger.v { "Will source ~/.lldbinit." }
47+
if (Console.confirm("Do you want to source the '~/.lldbinit' file?")) {
48+
Console.muted("Will source ~/.lldbinit.")
5149
sourceMainLlvmInit
5250
} else {
5351
""
@@ -60,13 +58,13 @@ object LLDBInitManager {
6058

6159
val oldAndNewContentsSeparator = if (!oldContents.endsWith("\n")) "\n" else ""
6260
val newContents = oldContents + oldAndNewContentsSeparator + sourcePluginInit
63-
logger.v { "Saving new LLDB init to ${lldbInitXcodeFile.path}." }
61+
Console.muted("Saving new LLDB init to ${lldbInitXcodeFile.path}.")
6462
lldbInitXcodeFile.write(newContents.objc)
6563
}
6664

6765
fun uninstall() {
6866
if (isInstalled) {
69-
logger.v { "LLDB init script found, removing." }
67+
Console.muted("LLDB init script found, removing.")
7068
val oldContents = lldbInitXcodeFile.stringContents()
7169
val newContents = oldContents.stringByReplacingOccurrencesOfString(target = sourcePluginInit, withString = "")
7270
lldbInitXcodeFile.write(newContents.objc)
@@ -75,7 +73,6 @@ object LLDBInitManager {
7573
}
7674

7775
object Legacy {
78-
private val logger = Logger.withTag("LLDBInitManager")
7976
private val legacyImport = """
8077
command script import ~/Library/Developer/Xcode/Plug-ins/Kotlin.ideplugin/Contents/Resources/konan_lldb_config.py
8178
command script import ~/Library/Developer/Xcode/Plug-ins/Kotlin.ideplugin/Contents/Resources/konan_lldb.py
@@ -91,11 +88,11 @@ object LLDBInitManager {
9188

9289
fun uninstall() {
9390
if (isInstalled) {
94-
logger.v { "Legacy LLDB script initialization found, removing." }
91+
Console.muted("Legacy LLDB script initialization found, removing.")
9592
val oldContents = lldbInitXcodeFile.stringContents()
9693
val newContents = oldContents.stringByReplacingOccurrencesOfString(target = legacyImport, withString = "")
9794
lldbInitXcodeFile.write(newContents.objc)
9895
}
9996
}
10097
}
101-
}
98+
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package co.touchlab.xcode.cli
22

3-
import co.touchlab.kermit.Logger
3+
import co.touchlab.xcode.cli.util.Console
44
import co.touchlab.xcode.cli.util.File
55
import co.touchlab.xcode.cli.util.Path
66

@@ -9,21 +9,20 @@ object LangSpecManager {
99
private val specSourceFile = File(Path.dataDir / specName)
1010
private val specsDirectory = File(XcodeHelper.xcodeLibraryPath / "Specifications")
1111
private val specTargetFile = File(specsDirectory.path / specName)
12-
private val logger = Logger.withTag("LangSpecManager")
1312

1413
val isInstalled: Boolean
1514
get() = specTargetFile.exists()
1615

1716
fun install() {
1817
check(!specTargetFile.exists()) { "Language spec file exists at path ${specTargetFile.path}! Delete it first." }
19-
logger.v { "Ensuring language specification directory exists at ${specsDirectory.path}" }
18+
Console.muted("Ensuring language specification directory exists at ${specsDirectory.path}")
2019
specsDirectory.mkdirs()
21-
logger.v { "Copying language specification to target path ${specTargetFile.path}" }
20+
Console.muted("Copying language specification to target path ${specTargetFile.path}")
2221
specSourceFile.copy(specTargetFile.path)
2322
}
2423

2524
fun uninstall() {
26-
logger.v { "Deleting language specification from ${specTargetFile.path}." }
25+
Console.muted("Deleting language specification from ${specTargetFile.path}.")
2726
specTargetFile.delete()
2827
}
29-
}
28+
}

0 commit comments

Comments
 (0)