From b7de2728841bbe5a6e2d635c9455cfcd88a7ef9a Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 14 Apr 2017 21:06:07 +0300 Subject: [PATCH] CLI: support delimiter for array arguments The " " delimiter is used in kotlin-native (see K2NativeCompilerArguments) --- .../cli/common/arguments/parseCommandLineArguments.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt index 9b7c57c7ac3..7cdf188f19e 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt @@ -21,6 +21,7 @@ import java.lang.reflect.Field annotation class Argument( val value: String, val shortName: String = "", + val delimiter: String = ",", val valueDescription: String = "", val description: String ) @@ -81,15 +82,15 @@ fun parseCommandLineArguments(args: Array, result.duplicateArguments.put(argument.value, value) } - updateField(field, result, value) + updateField(field, result, value, argument.delimiter) } } -private fun updateField(field: Field, result: A, value: Any) { +private fun updateField(field: Field, result: A, value: Any, delimiter: String) { when (field.type) { Boolean::class.java, String::class.java -> field.set(result, value) Array::class.java -> { - val newElements = (value as String).split(",").toTypedArray() + val newElements = (value as String).split(delimiter).toTypedArray() @Suppress("UNCHECKED_CAST") val oldValue = field.get(result) as Array? field.set(result, if (oldValue != null) arrayOf(*oldValue, *newElements) else newElements)