[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,
) = task {
DesktopType.valueOf(desktopType.name) // throws exception when desktopType.name is unknown
if (!currentUserCanSudo()) {
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
protected val values = listOf(BASIC, OFFICE, IDE)
fun valueOf(value: String): DesktopType {
return valueOf(value, values)
}
fun valueOf(value: String, v: List<DesktopType>): DesktopType {
for (t in v) {
if (value.uppercase().equals(t.name)) {
return t
fun valueOf(value: String, valueList: List<DesktopType> = values): DesktopType {
for (type in valueList) {
if (value.uppercase().equals(type.name)) {
return type
}
}
throw RuntimeException("No DesktopType found for value: $value")