Skip to content

Commit

Permalink
Fix #73
Browse files Browse the repository at this point in the history
  • Loading branch information
khud committed May 18, 2021
1 parent e29513d commit 2e98ee5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions ki-shell/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jetbrains.kotlinx.ki.shell

import java.util.*
import kotlin.NoSuchElementException

object ApplicationProperties {
private val props: Properties = Properties()

val version: String
get() = get("project.version")

fun get(key: String): String {
if (props.isEmpty) {
val inputStream = javaClass.getResourceAsStream("/application.properties")
inputStream.use {
props.load(inputStream)
}
}
return props.getProperty(key) ?: throw NoSuchElementException(key)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.jetbrains.kotlinx.ki.shell

import kotlinx.cli.CommandLineInterface
import kotlinx.cli.flagArgument
import kotlinx.cli.parse
import org.jetbrains.kotlinx.ki.shell.configuration.CachedInstance
import org.jetbrains.kotlinx.ki.shell.configuration.ReplConfiguration
import org.jetbrains.kotlinx.ki.shell.configuration.ReplConfigurationBase
Expand All @@ -11,8 +14,18 @@ import kotlin.script.experimental.jvm.dependenciesFromClassloader
import kotlin.script.experimental.jvm.jvm

object KotlinShell {
private val cli = CommandLineInterface("ki", printHelpByDefault = false)
private val version by cli.flagArgument("--version", "Print version")

@JvmStatic
fun main(args: Array<String>) {
cli.parse(args)

if (version) {
printVersion()
return
}

val repl = Shell(
configuration(),
defaultJvmScriptingHostConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,9 @@ open class Shell(val replConfiguration: ReplConfiguration,
}

private fun sayHello() {
println("ki-shell $VERSION/${KotlinVersion.CURRENT}")
printVersion()
replConfiguration.plugins().forEach { it.sayHello() }
}

companion object {
const val VERSION: String = "0.3"
}
}

class OnCompile(private val data: LinkedSnippet<KJvmCompiledScript>) : Event<LinkedSnippet<KJvmCompiledScript>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import java.io.File
import java.util.*
import java.util.regex.Pattern

fun printVersion() {
val version = ApplicationProperties.version
println("ki-shell $version/${KotlinVersion.CURRENT}")
}

fun calcHumanReadableSize(bytes: Long, si: Boolean = false): String {
val unit = if (si) 1000 else 1024
Expand Down
1 change: 1 addition & 0 deletions ki-shell/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project.version=${project.version}

0 comments on commit 2e98ee5

Please sign in to comment.