CLI: support -language-version option in cli runner
This commit is contained in:
committed by
Space Team
parent
30131e289f
commit
6f8049ffd3
@@ -82,23 +82,24 @@ object Main {
|
|||||||
arguments.addAll(args.copyOfRange(i+1, args.size))
|
arguments.addAll(args.copyOfRange(i+1, args.size))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("-help" == arg || "-h" == arg) {
|
when {
|
||||||
|
"-help" == arg || "-h" == arg -> {
|
||||||
printUsageAndExit()
|
printUsageAndExit()
|
||||||
}
|
}
|
||||||
else if ("-version" == arg) {
|
"-version" == arg -> {
|
||||||
printVersionAndExit()
|
printVersionAndExit()
|
||||||
}
|
}
|
||||||
else if ("-classpath" == arg || "-cp" == arg) {
|
"-classpath" == arg || "-cp" == arg -> {
|
||||||
for (path in next().split(File.pathSeparator).filter(String::isNotEmpty)) {
|
for (path in next().split(File.pathSeparator).filter(String::isNotEmpty)) {
|
||||||
classpath.addPath(path)
|
classpath.addPath(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ("-compiler-path" == arg) {
|
"-compiler-path" == arg -> {
|
||||||
for (path in next().split(File.pathSeparator).filter(String::isNotEmpty)) {
|
for (path in next().split(File.pathSeparator).filter(String::isNotEmpty)) {
|
||||||
compilerClasspath.addPath(path)
|
compilerClasspath.addPath(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ("-howtorun" == arg) {
|
"-howtorun" == arg -> {
|
||||||
if (howtorun != HowToRun.GUESS) {
|
if (howtorun != HowToRun.GUESS) {
|
||||||
throw RunnerException("-howtorun is already set to ${howtorun.argName}")
|
throw RunnerException("-howtorun is already set to ${howtorun.argName}")
|
||||||
}
|
}
|
||||||
@@ -111,7 +112,7 @@ object Main {
|
|||||||
?: throw RunnerException("invalid argument to the option -howtorun $howToRunArg, valid arguments are: ${HowToRun.validValues}")
|
?: throw RunnerException("invalid argument to the option -howtorun $howToRunArg, valid arguments are: ${HowToRun.validValues}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ("-expression" == arg || "-e" == arg) {
|
"-expression" == arg || "-e" == arg -> {
|
||||||
if (howtorun != HowToRun.GUESS && howtorun != HowToRun.SCRIPT) {
|
if (howtorun != HowToRun.GUESS && howtorun != HowToRun.SCRIPT) {
|
||||||
throw RunnerException("expression evaluation is not compatible with -howtorun argument ${howtorun.argName}")
|
throw RunnerException("expression evaluation is not compatible with -howtorun argument ${howtorun.argName}")
|
||||||
}
|
}
|
||||||
@@ -119,31 +120,35 @@ object Main {
|
|||||||
restAsArguments()
|
restAsArguments()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
else if ("-no-stdlib" == arg) {
|
"-no-stdlib" == arg -> {
|
||||||
noStdLib = true
|
noStdLib = true
|
||||||
compilerArguments.add(arg)
|
compilerArguments.add(arg)
|
||||||
}
|
}
|
||||||
else if ("-no-reflect" == arg) {
|
"-no-reflect" == arg -> {
|
||||||
noReflect = true
|
noReflect = true
|
||||||
compilerArguments.add(arg)
|
compilerArguments.add(arg)
|
||||||
}
|
}
|
||||||
else if (arg.startsWith("-X")) {
|
arg.startsWith("-X") -> {
|
||||||
compilerArguments.add(arg)
|
compilerArguments.add(arg)
|
||||||
}
|
}
|
||||||
else if (arg.startsWith("-")) {
|
"-language-version" == arg -> {
|
||||||
|
compilerArguments.add(arg)
|
||||||
|
compilerArguments.add(next())
|
||||||
|
}
|
||||||
|
arg.startsWith("-") -> {
|
||||||
throw RunnerException("unknown option: $arg")
|
throw RunnerException("unknown option: $arg")
|
||||||
}
|
}
|
||||||
else if (howtorun == HowToRun.JAR || (howtorun == HowToRun.GUESS && arg.endsWith(".jar"))) {
|
howtorun == HowToRun.JAR || howtorun == HowToRun.GUESS && arg.endsWith(".jar") -> {
|
||||||
setRunner(JarRunner(arg))
|
setRunner(JarRunner(arg))
|
||||||
restAsArguments()
|
restAsArguments()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
else if (howtorun == HowToRun.SCRIPT || (howtorun == HowToRun.GUESS && arg.endsWith(".kts"))) {
|
howtorun == HowToRun.SCRIPT || howtorun == HowToRun.GUESS && arg.endsWith(".kts") -> {
|
||||||
setRunner(ScriptRunner(arg))
|
setRunner(ScriptRunner(arg))
|
||||||
restAsArguments()
|
restAsArguments()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
else {
|
else -> {
|
||||||
val workingDir = File(".")
|
val workingDir = File(".")
|
||||||
val classFile = File(arg)
|
val classFile = File(arg)
|
||||||
|
|
||||||
@@ -160,6 +165,7 @@ object Main {
|
|||||||
restAsArguments()
|
restAsArguments()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -192,6 +192,18 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testRunnerExpressionLanguageVersion20() {
|
||||||
|
runProcess(
|
||||||
|
"kotlin",
|
||||||
|
"-language-version", "2.0", "-e",
|
||||||
|
"println(args.joinToString())",
|
||||||
|
"-a",
|
||||||
|
"b",
|
||||||
|
expectedStdout = "-a, b\n",
|
||||||
|
expectedStderr = "warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features\n"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun testCommandlineProcessing() {
|
fun testCommandlineProcessing() {
|
||||||
runProcess(
|
runProcess(
|
||||||
"kotlin",
|
"kotlin",
|
||||||
|
|||||||
Reference in New Issue
Block a user