add only to cli

This commit is contained in:
ansgarz 2022-02-24 22:27:01 +01:00
parent 478f058fd7
commit 32e4c04175
6 changed files with 59 additions and 7 deletions

View file

@ -2,7 +2,7 @@
<configuration default="false" name="provs-desktop" type="JetRunConfigurationType"> <configuration default="false" name="provs-desktop" type="JetRunConfigurationType">
<option name="MAIN_CLASS_NAME" value="org.domaindrivenarchitecture.provs.desktop.application.ApplicationKt" /> <option name="MAIN_CLASS_NAME" value="org.domaindrivenarchitecture.provs.desktop.application.ApplicationKt" />
<module name="provs.main" /> <module name="provs.main" />
<option name="PROGRAM_PARAMETERS" value="-s provs -l myIdeConfig.yaml" /> <option name="PROGRAM_PARAMETERS" value="basic local -o provsbinaries" />
<shortenClasspath name="NONE" /> <shortenClasspath name="NONE" />
<method v="2"> <method v="2">
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />

View file

@ -28,23 +28,33 @@ open class CliArgumentsParser(name: String) : CliTargetParser(name) {
target, target,
passwordInteractive passwordInteractive
), ),
module.configFileName module.configFileName,
module.submodules
) )
} }
abstract class DesktopSubcommand(name: String, description: String) : Subcommand(name, description) { abstract class DesktopSubcommand(name: String, description: String) : Subcommand(name, description) {
var parsed: Boolean = false var parsed: Boolean = false
var configFileName: ConfigFileName? = null var configFileName: ConfigFileName? = null
var submodules: List<String>? = null
val cliConfigFileName by option( val cliConfigFileName by option(
ArgType.String, ArgType.String,
"config-file", "config-file",
"c", "c",
"the filename containing the yaml config", "the filename containing the yaml config",
) )
val only by option(
ArgType.String,
"only",
"o",
"provisions only parts (currently possible: provsbinaries)",
)
override fun execute() { override fun execute() {
configFileName = cliConfigFileName?.let { ConfigFileName(it) } configFileName = cliConfigFileName?.let { ConfigFileName(it) }
parsed = true parsed = true
submodules = only?.split(",")
} }
} }

View file

@ -8,6 +8,7 @@ class DesktopCliCommand(
val type: DesktopType, val type: DesktopType,
val target: TargetCliCommand, val target: TargetCliCommand,
val configFile: ConfigFileName?, val configFile: ConfigFileName?,
val submodules: List<String>? = null
) { ) {
fun isValid(): Boolean { fun isValid(): Boolean {
return target.isValid() return target.isValid()

View file

@ -14,14 +14,18 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.keys.provisionKeys
import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.currentUserCanSudo import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.currentUserCanSudo
import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.whoami import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.whoami
fun provisionDesktop(prov: Prov, cmd: DesktopCliCommand) { fun provisionDesktop(prov: Prov, cmd: DesktopCliCommand) {
// retrieve config // retrieve config
val conf = if (cmd.configFile != null) getConfig(cmd.configFile.fileName) else DesktopConfig() val conf = if (cmd.configFile != null) getConfig(cmd.configFile.fileName) else DesktopConfig()
with(conf) { if (cmd.submodules == null) {
prov.provisionWorkplace(cmd.type, ssh?.keyPair(), gpg?.keyPair(), gitUserName, gitEmail) prov.provisionWorkplace(cmd.type, conf.ssh?.keyPair(), conf.gpg?.keyPair(), conf.gitUserName, conf.gitEmail)
} else {
prov.provisionWorkplaceSubmodules(cmd.submodules)
} }
} }
/** /**
* Provisions software and configurations for a personal workplace. * Provisions software and configurations for a personal workplace.
* Offers the possibility to choose between different types. * Offers the possibility to choose between different types.
@ -36,7 +40,7 @@ fun Prov.provisionWorkplace(
gpg: KeyPair? = null, gpg: KeyPair? = null,
gitUserName: String? = null, gitUserName: String? = null,
gitEmail: String? = null, gitEmail: String? = null,
) = requireAll { ) = task {
if (!currentUserCanSudo()) { if (!currentUserCanSudo()) {
throw Exception("Current user ${whoami()} cannot execute sudo without entering a password! This is necessary to execute provisionWorkplace") throw Exception("Current user ${whoami()} cannot execute sudo without entering a password! This is necessary to execute provisionWorkplace")
@ -113,3 +117,19 @@ fun Prov.provisionWorkplace(
} }
ProvResult(true) ProvResult(true)
} }
/**
* Provisions submodules for a personal workplace.
*
* Prerequisites: module must already been installed
*/
fun Prov.provisionWorkplaceSubmodules(
submodules: List<String>
) = task {
if (submodules.contains(DesktopSubmodule.PROVSBINARIES.name.lowercase())) {
aptInstall("jarwrapper")
installProvsBinaries()
}
ProvResult(true)
}

View file

@ -1,5 +1,5 @@
package org.domaindrivenarchitecture.provs.desktop.domain package org.domaindrivenarchitecture.provs.desktop.domain
enum class Scope { enum class DesktopSubmodule {
PROVS PROVSBINARIES
} }

View file

@ -2,7 +2,9 @@ package org.domaindrivenarchitecture.provs.framework.extensions.workplace
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopType import org.domaindrivenarchitecture.provs.desktop.domain.DesktopType
import org.domaindrivenarchitecture.provs.desktop.domain.provisionWorkplace import org.domaindrivenarchitecture.provs.desktop.domain.provisionWorkplace
import org.domaindrivenarchitecture.provs.desktop.domain.provisionWorkplaceSubmodules
import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.fileExists
import org.domaindrivenarchitecture.provs.test.defaultTestContainer import org.domaindrivenarchitecture.provs.test.defaultTestContainer
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
@ -49,6 +51,25 @@ internal class ProvisionWorkplaceKtTest {
// then // then
assertTrue(res.success) assertTrue(res.success)
} }
@Test
@ContainerTest
fun provision_submodule_provsbinaries() {
// given
val prov = defaultTestContainer()
// when
val res = prov.provisionWorkplaceSubmodules(
listOf("provsbinaries")
)
// then
assertTrue(res.success)
assertTrue(defaultTestContainer().fileExists(" /usr/local/bin/provs-server.jar", sudo = true))
assertTrue(defaultTestContainer().fileExists(" /usr/local/bin/provs-desktop.jar", sudo = true))
}
} }