Skip to content

Commit

Permalink
Add JVM CLI target
Browse files Browse the repository at this point in the history
  • Loading branch information
jdamcd committed Dec 27, 2024
1 parent e4abc44 commit d255ae6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
14 changes: 14 additions & 0 deletions cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
kotlin("jvm")
application
}

application {
mainClass.set("com.jdamcd.arrivals.cli.CliKt")
}

dependencies {
implementation(project(":shared"))
implementation(libs.koin)
implementation(libs.kotlin.coroutines)
}
26 changes: 26 additions & 0 deletions cli/src/main/kotlin/com/jdamcd/arrivals/cli/Cli.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.jdamcd.arrivals.cli

import com.jdamcd.arrivals.Arrivals
import com.jdamcd.arrivals.initKoin
import kotlinx.coroutines.runBlocking
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

fun main(args: Array<String>) {
initKoin()
runBlocking {
CliApplication().run()
}
}

class CliApplication : KoinComponent {
private val arrivals: Arrivals by inject()

suspend fun run() {
val result = arrivals.latest()
println(result.station)
result.arrivals.forEach {
println("%-24s\t%6s".format(it.destination, it.time))
}
}
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref =
ktor-client-content-negotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktor" }
ktor-client-logging = { group = "io.ktor", name = "ktor-client-logging", version.ref = "ktor" }
ktor-client-macos = { group = "io.ktor", name = "ktor-client-darwin", version.ref = "ktor" }
ktor-client-jvm = { group = "io.ktor", name = "ktor-client-java", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktor" }
kotlin-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }
kotlin-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "dateTime" }
wire-runtime = { group = "com.squareup.wire", name = "wire-runtime", version.ref = "wire" }
okio = { group = "com.squareup.okio", name = "okio", version.ref = "okio" }
koin = { group = "io.insert-koin", name = "koin-core", version.ref = "koin" }
logging-nop = { group = "org.slf4j", name = "slf4j-nop", version = "2.0.16" }

coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutines" }
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ dependencyResolutionManagement {
}

rootProject.name = "Arrivals"
include(":shared")
include(":shared", ":cli")
5 changes: 5 additions & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ kotlin {
implementation(libs.kotest)
}

jvmMain.dependencies {
implementation(libs.ktor.client.jvm)
implementation(libs.logging.nop)
}

jvmTest.dependencies {
implementation(libs.coroutines.test)
implementation(libs.mockk)
Expand Down

0 comments on commit d255ae6

Please sign in to comment.