Switch cli expression evaluation argument syntax to -expression/-e
#KT-35414 fixed
This commit is contained in:
+5
-1
@@ -49,7 +49,11 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
|||||||
@Argument(value = "-no-reflect", description = "Don't automatically include Kotlin reflection into the classpath")
|
@Argument(value = "-no-reflect", description = "Don't automatically include Kotlin reflection into the classpath")
|
||||||
var noReflect: Boolean by FreezableVar(false)
|
var noReflect: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
@Argument(value = "-Xexpression", description = "Evaluate the given string as a Kotlin script")
|
@Argument(
|
||||||
|
value = "-expression",
|
||||||
|
shortName = "-e",
|
||||||
|
description = "Evaluate the given string as a Kotlin script"
|
||||||
|
)
|
||||||
var expression: String? by FreezableVar(null)
|
var expression: String? by FreezableVar(null)
|
||||||
|
|
||||||
@Argument(
|
@Argument(
|
||||||
|
|||||||
@@ -151,7 +151,8 @@ class ExpressionRunner(private val code: String) : RunnerWithCompiler() {
|
|||||||
override fun run(classpath: List<URL>, arguments: List<String>, compilerClasspath: List<URL>) {
|
override fun run(classpath: List<URL>, arguments: List<String>, compilerClasspath: List<URL>) {
|
||||||
val compilerArgs = ArrayList<String>().apply {
|
val compilerArgs = ArrayList<String>().apply {
|
||||||
addClasspathArgIfNeeded(classpath)
|
addClasspathArgIfNeeded(classpath)
|
||||||
add("-Xexpression=$code")
|
add("-expression")
|
||||||
|
add(code)
|
||||||
addAll(arguments)
|
addAll(arguments)
|
||||||
}
|
}
|
||||||
runCompiler(compilerClasspath, compilerArgs)
|
runCompiler(compilerClasspath, compilerArgs)
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
-Xexpression=val x = 2; System.err.println((args + listOf(2,1).map { (it * x).toString() }).joinToString())
|
-expression
|
||||||
|
val x = 2; System.err.println((args + listOf(2,1).map { (it * x).toString() }).joinToString())
|
||||||
--
|
--
|
||||||
a
|
a
|
||||||
b
|
b
|
||||||
|
|||||||
-1
@@ -19,7 +19,6 @@ where advanced options include:
|
|||||||
-Xdump-declarations-to=<path> Path to JSON file to dump Java to Kotlin declaration mappings
|
-Xdump-declarations-to=<path> Path to JSON file to dump Java to Kotlin declaration mappings
|
||||||
-Xdisable-standard-script Disable standard kotlin script support
|
-Xdisable-standard-script Disable standard kotlin script support
|
||||||
-Xemit-jvm-type-annotations Emit JVM type annotations in bytecode
|
-Xemit-jvm-type-annotations Emit JVM type annotations in bytecode
|
||||||
-Xexpression Evaluate the given string as a Kotlin script
|
|
||||||
-Xfriend-paths=<path> Paths to output directories for friend modules (whose internals should be visible)
|
-Xfriend-paths=<path> Paths to output directories for friend modules (whose internals should be visible)
|
||||||
-Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade
|
-Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade
|
||||||
-Xir-check-local-names Check that names of local classes and anonymous objects are the same in the IR backend as in the old backend
|
-Xir-check-local-names Check that names of local classes and anonymous objects are the same in the IR backend as in the old backend
|
||||||
|
|||||||
Vendored
+1
@@ -2,6 +2,7 @@ Usage: kotlinc-jvm <options> <source files>
|
|||||||
where possible options include:
|
where possible options include:
|
||||||
-classpath (-cp) <path> List of directories and JAR/ZIP archives to search for user class files
|
-classpath (-cp) <path> List of directories and JAR/ZIP archives to search for user class files
|
||||||
-d <directory|jar> Destination for generated class files
|
-d <directory|jar> Destination for generated class files
|
||||||
|
-expression (-e) Evaluate the given string as a Kotlin script
|
||||||
-include-runtime Include Kotlin runtime into the resulting JAR
|
-include-runtime Include Kotlin runtime into the resulting JAR
|
||||||
-java-parameters Generate metadata for Java 1.8 reflection on method parameters
|
-java-parameters Generate metadata for Java 1.8 reflection on method parameters
|
||||||
-jdk-home <path> Include a custom JDK from the specified location into the classpath instead of the default JAVA_HOME
|
-jdk-home <path> Include a custom JDK from the specified location into the classpath instead of the default JAVA_HOME
|
||||||
|
|||||||
+2
-2
@@ -50,7 +50,7 @@ class ScriptingWithCliCompilerTest {
|
|||||||
fun testExpression() {
|
fun testExpression() {
|
||||||
runWithK2JVMCompiler(
|
runWithK2JVMCompiler(
|
||||||
arrayOf(
|
arrayOf(
|
||||||
"-Xexpression",
|
"-expression",
|
||||||
"val x = 7; println(x * 6); for (arg in args) println(arg)",
|
"val x = 7; println(x * 6); for (arg in args) println(arg)",
|
||||||
"--",
|
"--",
|
||||||
"hi",
|
"hi",
|
||||||
@@ -64,7 +64,7 @@ class ScriptingWithCliCompilerTest {
|
|||||||
fun testExpressionWithComma() {
|
fun testExpressionWithComma() {
|
||||||
runWithK2JVMCompiler(
|
runWithK2JVMCompiler(
|
||||||
arrayOf(
|
arrayOf(
|
||||||
"-Xexpression",
|
"-expression",
|
||||||
"listOf(1,2)"
|
"listOf(1,2)"
|
||||||
),
|
),
|
||||||
listOf("\\[1, 2\\]")
|
listOf("\\[1, 2\\]")
|
||||||
|
|||||||
Reference in New Issue
Block a user