mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Fix property parsing bug in the cli (#596)
This commit is contained in:
@@ -64,6 +64,16 @@ class BaseOptions : OptionGroup() {
|
||||
throw CliException(message)
|
||||
}
|
||||
}
|
||||
|
||||
fun RawOption.associateProps():
|
||||
OptionWithValues<Map<String, String>, Pair<String, String>, Pair<String, String>> {
|
||||
return convert {
|
||||
val parts = it.split("=")
|
||||
if (parts.size <= 1) parts[0] to "true" else parts[0] to parts[1]
|
||||
}
|
||||
.multiple()
|
||||
.toMap()
|
||||
}
|
||||
}
|
||||
|
||||
private val defaults = CliBaseOptions()
|
||||
@@ -116,7 +126,7 @@ class BaseOptions : OptionGroup() {
|
||||
metavar = "<name=value>",
|
||||
help = "External property to set (repeatable)."
|
||||
)
|
||||
.associate()
|
||||
.associateProps()
|
||||
|
||||
val noCache: Boolean by
|
||||
option(names = arrayOf("--no-cache"), help = "Disable caching of packages")
|
||||
@@ -214,7 +224,7 @@ class BaseOptions : OptionGroup() {
|
||||
allowedModules = allowedModules.ifEmpty { null },
|
||||
allowedResources = allowedResources.ifEmpty { null },
|
||||
environmentVariables = envVars.ifEmpty { null },
|
||||
externalProperties = properties.mapValues { it.value.ifBlank { "true" } }.ifEmpty { null },
|
||||
externalProperties = properties.ifEmpty { null },
|
||||
modulePath = modulePath.ifEmpty { null },
|
||||
workingDir = workingDir,
|
||||
settings = settings,
|
||||
|
||||
@@ -45,10 +45,10 @@ class BaseCommandTest {
|
||||
|
||||
@Test
|
||||
fun `external properties without value default to 'true'`() {
|
||||
cmd.parse(arrayOf("-p", "flag1", "-p", "flag2", "-p", "FOO=bar"))
|
||||
cmd.parse(arrayOf("-p", "flag1", "-p", "flag2=", "-p", "FOO=bar"))
|
||||
val props = cmd.baseOptions.baseOptions(emptyList()).externalProperties
|
||||
|
||||
assertThat(props).isEqualTo(mapOf("flag1" to "true", "flag2" to "true", "FOO" to "bar"))
|
||||
assertThat(props).isEqualTo(mapOf("flag1" to "true", "flag2" to "", "FOO" to "bar"))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user