diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt index 89e372b..fe644e7 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt @@ -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") } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopType.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopType.kt index 8c5c374..385b537 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopType.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopType.kt @@ -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 { - for (t in v) { - if (value.uppercase().equals(t.name)) { - return t + fun valueOf(value: String, valueList: List = values): DesktopType { + for (type in valueList) { + if (value.uppercase().equals(type.name)) { + return type } } throw RuntimeException("No DesktopType found for value: $value")