[CLI][Minor] toArgumentStrings: Use List Builder (like) style
KTIJ-24976
This commit is contained in:
committed by
Space Team
parent
082a38216d
commit
b6ca62f330
@@ -30,9 +30,8 @@ internal fun <T : CommonToolArguments> toArgumentStrings(
|
|||||||
thisArguments: T, type: KClass<T>,
|
thisArguments: T, type: KClass<T>,
|
||||||
shortArgumentKeys: Boolean,
|
shortArgumentKeys: Boolean,
|
||||||
compactArgumentValues: Boolean
|
compactArgumentValues: Boolean
|
||||||
): List<String> {
|
): List<String> = ArrayList<String>().apply {
|
||||||
val defaultArguments = type.newArgumentsInstance()
|
val defaultArguments = type.newArgumentsInstance()
|
||||||
val result = mutableListOf<String>()
|
|
||||||
type.memberProperties.forEach { property ->
|
type.memberProperties.forEach { property ->
|
||||||
val argumentAnnotation = property.findAnnotation<Argument>() ?: return@forEach
|
val argumentAnnotation = property.findAnnotation<Argument>() ?: return@forEach
|
||||||
val rawPropertyValue = property.get(thisArguments)
|
val rawPropertyValue = property.get(thisArguments)
|
||||||
@@ -63,24 +62,23 @@ internal fun <T : CommonToolArguments> toArgumentStrings(
|
|||||||
when {
|
when {
|
||||||
/* We can just enable the flag by passing the argument name like -myFlag: Value not required */
|
/* We can just enable the flag by passing the argument name like -myFlag: Value not required */
|
||||||
rawPropertyValue is Boolean && rawPropertyValue -> {
|
rawPropertyValue is Boolean && rawPropertyValue -> {
|
||||||
result.add(argumentName)
|
add(argumentName)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Advanced (e.g. -X arguments) or boolean properties need to be passed using the '=' */
|
/* Advanced (e.g. -X arguments) or boolean properties need to be passed using the '=' */
|
||||||
argumentAnnotation.isAdvanced || property.returnType.classifier == Boolean::class -> {
|
argumentAnnotation.isAdvanced || property.returnType.classifier == Boolean::class -> {
|
||||||
result.add("$argumentName=$argumentStringValue")
|
add("$argumentName=$argumentStringValue")
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
result.add(argumentName)
|
add(argumentName)
|
||||||
result.add(argumentStringValue)
|
add(argumentStringValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.addAll(thisArguments.freeArgs)
|
addAll(thisArguments.freeArgs)
|
||||||
result.addAll(thisArguments.internalArguments.map { it.stringRepresentation })
|
addAll(thisArguments.internalArguments.map { it.stringRepresentation })
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getArgumentStringValue(argumentAnnotation: Argument, values: Array<*>?, compactArgumentValues: Boolean): List<String> {
|
private fun getArgumentStringValue(argumentAnnotation: Argument, values: Array<*>?, compactArgumentValues: Boolean): List<String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user