Reintroduce Clitk extensions module

A future commit will introduce CLI options that need to be interpreted
as an Instant.

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent f3ea8e71fe
commit ab006bbf44
  1. 24
      cli/build.gradle.kts
  2. 17
      cli/src/main/kotlin/org/openrs2/cli/OptionExtensions.kt
  3. 1
      settings.gradle.kts

@ -0,0 +1,24 @@
plugins {
`maven-publish`
kotlin("jvm")
}
dependencies {
api("com.github.ajalt.clikt:clikt:${Versions.clikt}")
}
publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
pom {
packaging = "jar"
name.set("OpenRS2 CLI")
description.set(
"""
Clikt extensions.
""".trimIndent()
)
}
}
}

@ -0,0 +1,17 @@
package org.openrs2.cli
import com.github.ajalt.clikt.core.BadParameterValue
import com.github.ajalt.clikt.parameters.options.NullableOption
import com.github.ajalt.clikt.parameters.options.RawOption
import com.github.ajalt.clikt.parameters.options.convert
import java.time.Instant
import java.time.OffsetDateTime
import java.time.format.DateTimeParseException
public fun RawOption.instant(): NullableOption<Instant, Instant> = convert({ "TIMESTAMP" }) {
try {
OffsetDateTime.parse(it).toInstant()
} catch (ex: DateTimeParseException) {
throw BadParameterValue("$it is not a valid timestamp")
}
}

@ -6,6 +6,7 @@ include(
"asm",
"buffer",
"cache",
"cli",
"compress",
"compress-cli",
"conf",

Loading…
Cancel
Save