Skip to content

Commit 0cc592d

Browse files
authored
Merge pull request #78 from Kotlin/khud/0.3-fixes
Khud/0.3 fixes
2 parents cdf5666 + b671caa commit 0cc592d

File tree

6 files changed

+41
-5
lines changed

6 files changed

+41
-5
lines changed

ki-shell/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
<resources>
9292
<resource>
9393
<directory>${project.basedir}/src/main/resources</directory>
94+
<filtering>true</filtering>
9495
</resource>
9596
</resources>
9697
<plugins>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.jetbrains.kotlinx.ki.shell
2+
3+
import java.util.*
4+
import kotlin.NoSuchElementException
5+
6+
object ApplicationProperties {
7+
private val props: Properties = Properties()
8+
9+
val version: String
10+
get() = get("project.version")
11+
12+
fun get(key: String): String {
13+
if (props.isEmpty) {
14+
val inputStream = javaClass.getResourceAsStream("/application.properties")
15+
inputStream.use {
16+
props.load(inputStream)
17+
}
18+
}
19+
return props.getProperty(key) ?: throw NoSuchElementException(key)
20+
}
21+
}

ki-shell/src/main/kotlin/org/jetbrains/kotlinx/ki/shell/KotlinShell.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.jetbrains.kotlinx.ki.shell
22

3+
import kotlinx.cli.CommandLineInterface
4+
import kotlinx.cli.flagArgument
5+
import kotlinx.cli.parse
36
import org.jetbrains.kotlinx.ki.shell.configuration.CachedInstance
47
import org.jetbrains.kotlinx.ki.shell.configuration.ReplConfiguration
58
import org.jetbrains.kotlinx.ki.shell.configuration.ReplConfigurationBase
@@ -11,8 +14,18 @@ import kotlin.script.experimental.jvm.dependenciesFromClassloader
1114
import kotlin.script.experimental.jvm.jvm
1215

1316
object KotlinShell {
17+
private val cli = CommandLineInterface("ki", printHelpByDefault = false)
18+
private val version by cli.flagArgument("--version", "Print version")
19+
1420
@JvmStatic
1521
fun main(args: Array<String>) {
22+
cli.parse(args)
23+
24+
if (version) {
25+
printVersion()
26+
return
27+
}
28+
1629
val repl = Shell(
1730
configuration(),
1831
defaultJvmScriptingHostConfiguration,

ki-shell/src/main/kotlin/org/jetbrains/kotlinx/ki/shell/Shell.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,9 @@ open class Shell(val replConfiguration: ReplConfiguration,
321321
}
322322

323323
private fun sayHello() {
324-
println("ki-shell $VERSION/${KotlinVersion.CURRENT}")
324+
printVersion()
325325
replConfiguration.plugins().forEach { it.sayHello() }
326326
}
327-
328-
companion object {
329-
const val VERSION: String = "0.3"
330-
}
331327
}
332328

333329
class OnCompile(private val data: LinkedSnippet<KJvmCompiledScript>) : Event<LinkedSnippet<KJvmCompiledScript>> {

ki-shell/src/main/kotlin/org/jetbrains/kotlinx/ki/shell/Util.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import java.io.File
44
import java.util.*
55
import java.util.regex.Pattern
66

7+
fun printVersion() {
8+
val version = ApplicationProperties.version
9+
println("ki-shell $version/${KotlinVersion.CURRENT}")
10+
}
711

812
fun calcHumanReadableSize(bytes: Long, si: Boolean = false): String {
913
val unit = if (si) 1000 else 1024
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
project.version=${project.version}

0 commit comments

Comments
 (0)