Skip to content

Commit c2618dc

Browse files
committed
Basic CLI args
1 parent 32b9eec commit c2618dc

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
uses: dorny/test-reporter@v1.9.1
4242
if: always()
4343
with:
44-
name: Kotlin results
44+
name: Test results
4545
path: '**/build/test-results/**/TEST-*.xml'
4646
reporter: java-junit
4747
fail-on-error: true

cli/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ dependencies {
1111
implementation(project(":shared"))
1212
implementation(libs.koin)
1313
implementation(libs.kotlin.coroutines)
14+
implementation(libs.clikt)
1415
}
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package com.jdamcd.arrivals.cli
22

3+
import com.github.ajalt.clikt.command.SuspendingCliktCommand
4+
import com.github.ajalt.clikt.command.main
5+
import com.github.ajalt.clikt.parameters.options.default
6+
import com.github.ajalt.clikt.parameters.options.option
7+
import com.github.ajalt.clikt.parameters.types.choice
38
import com.jdamcd.arrivals.Arrivals
9+
import com.jdamcd.arrivals.Settings
10+
import com.jdamcd.arrivals.SettingsConfig
411
import com.jdamcd.arrivals.initKoin
512
import kotlinx.coroutines.runBlocking
613
import org.koin.core.component.KoinComponent
@@ -9,18 +16,27 @@ import org.koin.core.component.inject
916
fun main(args: Array<String>) {
1017
initKoin()
1118
runBlocking {
12-
CliApplication().run()
19+
Cli().main(args)
1320
}
1421
}
1522

16-
class CliApplication : KoinComponent {
23+
private class Cli :
24+
SuspendingCliktCommand("arrivals"),
25+
KoinComponent {
1726
private val arrivals: Arrivals by inject()
27+
private val settings: Settings by inject()
28+
29+
val mode by option().choice("tfl", "gtfs").default("tfl")
30+
31+
override suspend fun run() {
32+
if (mode == "gtfs") {
33+
settings.mode = SettingsConfig.MODE_GTFS
34+
}
1835

19-
suspend fun run() {
2036
val result = arrivals.latest()
21-
println(result.station)
37+
echo(result.station)
2238
result.arrivals.forEach {
23-
println("%-24s\t%6s".format(it.destination, it.time))
39+
echo("%-24s\t%6s".format(it.destination, it.time))
2440
}
2541
}
2642
}

gradle/libs.versions.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ okio = "3.9.1"
1111
koin = "4.0.0"
1212
mockk = "1.13.14"
1313
kotest = "5.9.1"
14+
logging = "2.0.16"
15+
clikt = "5.0.2"
1416

1517
[libraries]
1618
ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" }
@@ -24,7 +26,8 @@ kotlin-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime",
2426
wire-runtime = { group = "com.squareup.wire", name = "wire-runtime", version.ref = "wire" }
2527
okio = { group = "com.squareup.okio", name = "okio", version.ref = "okio" }
2628
koin = { group = "io.insert-koin", name = "koin-core", version.ref = "koin" }
27-
logging-nop = { group = "org.slf4j", name = "slf4j-nop", version = "2.0.16" }
29+
logging-nop = { group = "org.slf4j", name = "slf4j-nop", version.ref = "logging" }
30+
clikt = { group = "com.github.ajalt.clikt", name = "clikt", version.ref = "clikt" }
2831

2932
coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutines" }
3033
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }

shared/src/commonMain/kotlin/com/jdamcd/arrivals/gtfs/GtfsApi.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ internal class GtfsApi(private val client: HttpClient) {
5656
val fileToWrite = destination.resolve(relativePath)
5757
fileToWrite.createParentDirectories()
5858
FileSystem.SYSTEM.sink(fileToWrite).buffer().use { sink ->
59-
val bytes = sink.writeAll(source)
60-
println("Unzipped: $relativePath to $fileToWrite; $bytes bytes written")
59+
sink.writeAll(source)
6160
}
6261
}
6362
}

0 commit comments

Comments
 (0)