Skip to content

Commit

Permalink
Merge pull request #4 from wttech/fix/fix-backslash-for-pathfields-on…
Browse files Browse the repository at this point in the history
…-windows
  • Loading branch information
jaroslaw-pietraszek-vml authored Apr 18, 2023
2 parents d3da266 + d0b01fb commit 8156ac3
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,21 @@ class StringProp(group: Group, name: String) : Prop(group, name) {

fun password() = valueTypePassword()

fun path() = valueTypePath()

val valueType = project.objects.property(ValueType::class.java).convention(ValueType.STRING)

enum class ValueType {
STRING,
PATH,
PASSWORD,
INT,
DOUBLE,
BOOL
}

fun valueTypeString() { valueType.set(ValueType.STRING) }
fun valueTypePath() { valueType.set(ValueType.PATH) }
fun valueTypePassword() { valueType.set(ValueType.PASSWORD) }
fun valueTypeInt() { valueType.set(ValueType.INT) }
fun valueTypeDouble() { valueType.set(ValueType.DOUBLE) }
Expand All @@ -66,6 +70,7 @@ class StringProp(group: Group, name: String) : Prop(group, name) {

private var valueSaved: (String?) -> Any? = { v ->
when (valueType.get()) {
ValueType.PATH -> v?.let { v.replace("\\", "/") }
ValueType.BOOL -> v?.toBoolean()
ValueType.INT -> v?.toInt()
ValueType.DOUBLE -> v?.toDouble()
Expand Down Expand Up @@ -116,6 +121,7 @@ class StringProp(group: Group, name: String) : Prop(group, name) {

init {
when { // name-based smart defaults
listOf("path", "directory", "URL").any { name.endsWith(it, true) } -> path()
listOf("token", "password", "key").any { name.endsWith(it, true) } -> password()
listOf("enabled", "disabled").any { name.endsWith(it, true) } -> checkbox()
}
Expand Down

0 comments on commit 8156ac3

Please sign in to comment.