[skip-ci] refactor: removed overloaded valueOf

This commit is contained in:
see 2022-06-17 13:01:04 +02:00
parent 27f090557a
commit 15dfba6b6e
2 changed files with 6 additions and 7 deletions

View file

@ -43,6 +43,8 @@ fun Prov.provisionDesktop(
gitEmail: String? = null, gitEmail: String? = null,
) = task { ) = task {
DesktopType.valueOf(desktopType.name) // throws exception when desktopType.name is unknown
if (!currentUserCanSudo()) { if (!currentUserCanSudo()) {
throw Exception("Current user ${whoami()} cannot execute sudo without entering a password! This is necessary to execute provisionDesktop") throw Exception("Current user ${whoami()} cannot execute sudo without entering a password! This is necessary to execute provisionDesktop")
} }

View file

@ -17,13 +17,10 @@ open class DesktopType(val name: String) {
@JvmStatic @JvmStatic
protected val values = listOf(BASIC, OFFICE, IDE) protected val values = listOf(BASIC, OFFICE, IDE)
fun valueOf(value: String): DesktopType { fun valueOf(value: String, valueList: List<DesktopType> = values): DesktopType {
return valueOf(value, values) for (type in valueList) {
} if (value.uppercase().equals(type.name)) {
fun valueOf(value: String, v: List<DesktopType>): DesktopType { return type
for (t in v) {
if (value.uppercase().equals(t.name)) {
return t
} }
} }
throw RuntimeException("No DesktopType found for value: $value") throw RuntimeException("No DesktopType found for value: $value")