mirror of
https://github.com/apple/pkl.git
synced 2026-04-24 09:18:35 +02:00
Fix property parsing bug in the cli (#596)
This commit is contained in:
@@ -64,6 +64,16 @@ class BaseOptions : OptionGroup() {
|
|||||||
throw CliException(message)
|
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()
|
private val defaults = CliBaseOptions()
|
||||||
@@ -116,7 +126,7 @@ class BaseOptions : OptionGroup() {
|
|||||||
metavar = "<name=value>",
|
metavar = "<name=value>",
|
||||||
help = "External property to set (repeatable)."
|
help = "External property to set (repeatable)."
|
||||||
)
|
)
|
||||||
.associate()
|
.associateProps()
|
||||||
|
|
||||||
val noCache: Boolean by
|
val noCache: Boolean by
|
||||||
option(names = arrayOf("--no-cache"), help = "Disable caching of packages")
|
option(names = arrayOf("--no-cache"), help = "Disable caching of packages")
|
||||||
@@ -214,7 +224,7 @@ class BaseOptions : OptionGroup() {
|
|||||||
allowedModules = allowedModules.ifEmpty { null },
|
allowedModules = allowedModules.ifEmpty { null },
|
||||||
allowedResources = allowedResources.ifEmpty { null },
|
allowedResources = allowedResources.ifEmpty { null },
|
||||||
environmentVariables = envVars.ifEmpty { null },
|
environmentVariables = envVars.ifEmpty { null },
|
||||||
externalProperties = properties.mapValues { it.value.ifBlank { "true" } }.ifEmpty { null },
|
externalProperties = properties.ifEmpty { null },
|
||||||
modulePath = modulePath.ifEmpty { null },
|
modulePath = modulePath.ifEmpty { null },
|
||||||
workingDir = workingDir,
|
workingDir = workingDir,
|
||||||
settings = settings,
|
settings = settings,
|
||||||
|
|||||||
@@ -45,10 +45,10 @@ class BaseCommandTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `external properties without value default to 'true'`() {
|
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
|
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
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user