add only to cli
This commit is contained in:
parent
478f058fd7
commit
32e4c04175
6 changed files with 59 additions and 7 deletions
|
@ -2,7 +2,7 @@
|
|||
<configuration default="false" name="provs-desktop" type="JetRunConfigurationType">
|
||||
<option name="MAIN_CLASS_NAME" value="org.domaindrivenarchitecture.provs.desktop.application.ApplicationKt" />
|
||||
<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" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
|
|
|
@ -28,23 +28,33 @@ open class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
|||
target,
|
||||
passwordInteractive
|
||||
),
|
||||
module.configFileName
|
||||
module.configFileName,
|
||||
module.submodules
|
||||
)
|
||||
}
|
||||
|
||||
abstract class DesktopSubcommand(name: String, description: String) : Subcommand(name, description) {
|
||||
var parsed: Boolean = false
|
||||
var configFileName: ConfigFileName? = null
|
||||
var submodules: List<String>? = null
|
||||
|
||||
val cliConfigFileName by option(
|
||||
ArgType.String,
|
||||
"config-file",
|
||||
"c",
|
||||
"the filename containing the yaml config",
|
||||
)
|
||||
val only by option(
|
||||
ArgType.String,
|
||||
"only",
|
||||
"o",
|
||||
"provisions only parts (currently possible: provsbinaries)",
|
||||
)
|
||||
|
||||
override fun execute() {
|
||||
configFileName = cliConfigFileName?.let { ConfigFileName(it) }
|
||||
parsed = true
|
||||
submodules = only?.split(",")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ class DesktopCliCommand(
|
|||
val type: DesktopType,
|
||||
val target: TargetCliCommand,
|
||||
val configFile: ConfigFileName?,
|
||||
val submodules: List<String>? = null
|
||||
) {
|
||||
fun isValid(): Boolean {
|
||||
return target.isValid()
|
||||
|
|
|
@ -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.whoami
|
||||
|
||||
|
||||
fun provisionDesktop(prov: Prov, cmd: DesktopCliCommand) {
|
||||
// retrieve config
|
||||
val conf = if (cmd.configFile != null) getConfig(cmd.configFile.fileName) else DesktopConfig()
|
||||
with(conf) {
|
||||
prov.provisionWorkplace(cmd.type, ssh?.keyPair(), gpg?.keyPair(), gitUserName, gitEmail)
|
||||
if (cmd.submodules == null) {
|
||||
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.
|
||||
* Offers the possibility to choose between different types.
|
||||
|
@ -36,7 +40,7 @@ fun Prov.provisionWorkplace(
|
|||
gpg: KeyPair? = null,
|
||||
gitUserName: String? = null,
|
||||
gitEmail: String? = null,
|
||||
) = requireAll {
|
||||
) = task {
|
||||
|
||||
if (!currentUserCanSudo()) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
package org.domaindrivenarchitecture.provs.desktop.domain
|
||||
|
||||
enum class Scope {
|
||||
PROVS
|
||||
enum class DesktopSubmodule {
|
||||
PROVSBINARIES
|
||||
}
|
|
@ -2,7 +2,9 @@ package org.domaindrivenarchitecture.provs.framework.extensions.workplace
|
|||
|
||||
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopType
|
||||
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.framework.ubuntu.filesystem.base.fileExists
|
||||
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
||||
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
|
@ -49,6 +51,25 @@ internal class ProvisionWorkplaceKtTest {
|
|||
// then
|
||||
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))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue