Skip to content

Add version number to CLI output #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,26 @@ subprojects {

})
plugins.withId('org.jetbrains.kotlin.jvm', { _ ->
def generatedVersionDir = "${buildDir}/generated-version"

sourceSets {
main.kotlin.srcDirs = ["src"]
test.kotlin.srcDirs = ["test"]

main {
output.dir(generatedVersionDir, builtBy: 'generateVersionProperties')
}
}
task generateVersionProperties {
doLast {
def propertiesFile = file "$generatedVersionDir/version.properties"
propertiesFile.parentFile.mkdirs()
def properties = new Properties()
properties.setProperty("version", version.toString())
propertiesFile.withWriter { properties.store(it, null) }
}
}
processResources.dependsOn generateVersionProperties
})

}
Expand Down
15 changes: 13 additions & 2 deletions cli/src/org/partiql/cli/Repl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import com.amazon.ion.system.*
import com.amazon.ionelement.api.toIonValue
import org.partiql.cli.ReplState.*
import org.partiql.lang.*
import org.partiql.lang.ast.*
import org.partiql.lang.ast.passes.MetaStrippingRewriter
import org.partiql.lang.eval.*
import org.partiql.lang.syntax.*
import org.partiql.lang.util.*
import java.io.*
import java.util.Properties
import java.util.concurrent.*

internal const val PROMPT_1 = "PartiQL> "
Expand Down Expand Up @@ -192,6 +191,17 @@ internal class Repl(private val valueFactory: ExprValueFactory,
outputWriter.write("\n")
}

fun retrievePartiQLVersion(): String {
val versionProperties = Properties()
versionProperties.load(this.javaClass.getResourceAsStream("/version.properties"))
return versionProperties.getProperty("version")
}

private fun printVersionNumber() {
outputWriter.write("Using version: ${retrievePartiQLVersion()}")
outputWriter.write("\n")
}

private fun printPrompt() {
when {
buffer.isEmpty() -> outputWriter.write(PROMPT_1)
Expand Down Expand Up @@ -268,6 +278,7 @@ internal class Repl(private val valueFactory: ExprValueFactory,
state = when (state) {
INIT -> {
printWelcomeMessage()
printVersionNumber()
READY
}

Expand Down
65 changes: 17 additions & 48 deletions cli/test/org/partiql/cli/ReplTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ private class ReplTester(bindings: Bindings<ExprValue> = Bindings.empty()) {

private val repl = Repl(valueFactory, input, output, parser, compiler, bindings, zeroTimer)

val partiqlVersion = repl.retrievePartiQLVersion()

private val actualReplPrompt = StringBuilder()

private val outputPhaser = Phaser()
Expand Down Expand Up @@ -148,11 +150,13 @@ private class ReplTester(bindings: Bindings<ExprValue> = Bindings.empty()) {

@Ignore("https://github.com/partiql/partiql-lang-kotlin/issues/266")
class ReplTest {
private val partiqlVersion = ReplTester().partiqlVersion

@Test
fun singleQuery() {
ReplTester().assertReplPrompt("""
#Welcome to the PartiQL REPL!
#Using version: $partiqlVersion
#PartiQL> 1+1
# |
#==='
Expand All @@ -167,6 +171,7 @@ class ReplTest {
fun querySemiColon() {
ReplTester().assertReplPrompt("""
#Welcome to the PartiQL REPL!
#Using version: $partiqlVersion
#PartiQL> 1+1;
#==='
#2
Expand All @@ -180,6 +185,7 @@ class ReplTest {
fun multipleQuery() {
ReplTester().assertReplPrompt("""
#Welcome to the PartiQL REPL!
#Using version: $partiqlVersion
#PartiQL> 1 + 1
# |
#==='
Expand All @@ -201,66 +207,24 @@ class ReplTest {
fun astWithoutMetas() {
ReplTester().assertReplPrompt("""
#Welcome to the PartiQL REPL!
#Using version: $partiqlVersion
#PartiQL> 1 + 1
# | !!
#==='
#
#(
# plus
# (
# lit
# 1
# )
# (
# lit
# 1
# )
#)
#---
#OK!
#PartiQL>
""".trimMargin("#"))
}

@Test
fun astWithMetas() {
ReplTester().assertReplPrompt("""
#Welcome to the PartiQL REPL!
#PartiQL> 1 + 1
# | !?
Comment on lines -225 to -230
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was removed due to removal of printing ASTs without metas in #272.

#==='
#
#(
# meta
# query
Comment on lines 215 to +216
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix to the existing test's AST.

# (
# plus
# (
# meta
# (
# lit
# 1
# )
# {
# line:1,
# column:1
# }
# lit
# 1
# )
# (
# meta
# (
# lit
# 1
# )
# {
# line:1,
# column:5
# }
# lit
# 1
# )
# )
# {
# line:1,
# column:3
# }
#)
#---
#OK!
Expand All @@ -272,6 +236,7 @@ class ReplTest {
fun addToGlobalEnvAndQuery() {
ReplTester().assertReplPrompt("""
#Welcome to the PartiQL REPL!
#Using version: $partiqlVersion
#PartiQL> !add_to_global_env {'myTable': <<{'a':1}, {'a': 2}>>}
# |
#==='
Expand Down Expand Up @@ -314,6 +279,7 @@ class ReplTest {

ReplTester(initialBindings).assertReplPrompt("""
#Welcome to the PartiQL REPL!
#Using version: $partiqlVersion
#PartiQL> !global_env
# |
#==='
Expand All @@ -334,6 +300,7 @@ class ReplTest {
fun dumpEmptyInitialEnv() {
ReplTester().assertReplPrompt("""
#Welcome to the PartiQL REPL!
#Using version: $partiqlVersion
#PartiQL> !global_env
# |
#==='
Expand All @@ -348,6 +315,7 @@ class ReplTest {
fun dumpEnvAfterAltering() {
ReplTester().assertReplPrompt("""
#Welcome to the PartiQL REPL!
#Using version: $partiqlVersion
#PartiQL> !add_to_global_env {'myTable': <<{'a':1}, {'a': 2}>>}
# |
#==='
Expand Down Expand Up @@ -386,6 +354,7 @@ class ReplTest {
fun listCommands() {
ReplTester().assertReplPrompt("""
#Welcome to the PartiQL REPL!
#Using version: $partiqlVersion
#PartiQL> !list_commands
# |
#
Expand Down