v0.8.32 simplify cli
This commit is contained in:
parent
835d777c90
commit
2ea30ab6c2
6 changed files with 46 additions and 56 deletions
|
@ -18,7 +18,7 @@ apply plugin: 'kotlinx-serialization'
|
|||
|
||||
|
||||
group = 'org.domaindrivenarchitecture.provs'
|
||||
version = '0.8.32-SNAPSHOT'
|
||||
version = '0.8.32'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
|
|
@ -11,7 +11,8 @@ participant User
|
|||
box "application" #LightBlue
|
||||
|
||||
participant CliWorkplace
|
||||
participant WorkplaceCliCommand
|
||||
participant CliWorkplaceParser
|
||||
participant CliWorkplaceCommand
|
||||
participant Application
|
||||
|
||||
end box
|
||||
|
@ -19,46 +20,42 @@ end box
|
|||
box #White
|
||||
|
||||
participant CliUtils
|
||||
participant "ProvInstance (local, remote...)" as ProvInstance
|
||||
participant "Prov (local or remote...)" as ProvInstance
|
||||
|
||||
end box
|
||||
|
||||
box "domain" #LightGreen
|
||||
|
||||
participant ProvisionWorkplace
|
||||
participant WorkplaceConfig
|
||||
|
||||
end box
|
||||
|
||||
box "infrastructure" #CornSilk
|
||||
|
||||
participant ConfigRepository
|
||||
participant InfrastructureModules
|
||||
participant "Infrastructure functions" as Infrastructure_functions
|
||||
|
||||
end box
|
||||
|
||||
|
||||
User -> CliWorkplace ++ : main(args...)
|
||||
|
||||
CliWorkplace -> WorkplaceCliCommand : parseWorkplaceArguments
|
||||
CliWorkplace -> CliWorkplaceParser : parseWorkplaceArguments
|
||||
|
||||
CliWorkplace -> WorkplaceCliCommand : isValid ?
|
||||
CliWorkplace -> CliWorkplaceCommand : isValid ?
|
||||
|
||||
CliWorkplace -> ConfigRepository : getConfig
|
||||
|
||||
CliWorkplace -> CliUtils : createProvInstance
|
||||
ProvInstance <- CliUtils : create
|
||||
|
||||
CliWorkplace -> ConfigRepository : getConfig
|
||||
WorkplaceConfig <- ConfigRepository : create
|
||||
WorkplaceConfig --> ConfigRepository : config
|
||||
CliWorkplace <-- ConfigRepository : config
|
||||
|
||||
CliWorkplace -> Application : provision ( config )
|
||||
Application -> ProvInstance : provisionWorkplace ( type, ssh, ...)
|
||||
ProvInstance -> ProvisionWorkplace : provisionWorkplace
|
||||
|
||||
ProvisionWorkplace -> InfrastructureModules: Various calls like:
|
||||
ProvisionWorkplace -> InfrastructureModules: install ssh, gpg, git ...
|
||||
ProvisionWorkplace -> InfrastructureModules: installVirtualBoxGuestAdditions
|
||||
ProvisionWorkplace -> InfrastructureModules: configureNoSwappiness, ...
|
||||
ProvisionWorkplace -> Infrastructure_functions: Various calls like:
|
||||
ProvisionWorkplace -> Infrastructure_functions: install ssh, gpg, git ...
|
||||
ProvisionWorkplace -> Infrastructure_functions: installVirtualBoxGuestAdditions
|
||||
ProvisionWorkplace -> Infrastructure_functions: configureNoSwappiness, ...
|
||||
|
||||
@enduml
|
||||
|
|
|
@ -20,7 +20,7 @@ import kotlin.system.exitProcess
|
|||
* If the target is remote and if parameter remoteHostSetSudoWithoutPasswordRequired is set to true,
|
||||
* it will enable sudo without password on the remote machine (in case this was not yet enabled).
|
||||
*/
|
||||
internal fun createProvInstance(
|
||||
fun createProvInstance(
|
||||
targetCommand: TargetCliCommand,
|
||||
remoteHostSetSudoWithoutPasswordRequired: Boolean = false
|
||||
): Prov {
|
||||
|
|
|
@ -1,41 +1,35 @@
|
|||
package org.domaindrivenarchitecture.provs.workplace.application
|
||||
|
||||
import org.domaindrivenarchitecture.provs.core.cli.createProvInstance
|
||||
import org.domaindrivenarchitecture.provs.workplace.application.WorkplaceCliCommand.Companion.parseWorkplaceArguments
|
||||
import org.domaindrivenarchitecture.provs.workplace.infrastructure.getConfig
|
||||
import java.io.File
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
|
||||
/**
|
||||
* Provisions a workplace locally or on a remote machine.
|
||||
* Specify option -h for help.
|
||||
* Provisions a workplace locally or on a remote machine. Use option -h for help.
|
||||
*/
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
val cmd = parseWorkplaceArguments("java -jar provs.jar", args)
|
||||
val cmd = CliWorkplaceParser("java -jar provs.jar").parseWorkplaceArguments(args)
|
||||
|
||||
if (!cmd.isValid()) {
|
||||
println("Arguments are not valid, pls try -h for help.")
|
||||
println("Arguments are not valid, pls try option -h for help.")
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
provisionWorkplace(cmd)
|
||||
}
|
||||
|
||||
|
||||
private fun provisionWorkplace(cliCommand: WorkplaceCliCommand) {
|
||||
val filename = cliCommand.configFile
|
||||
|
||||
try {
|
||||
val conf = getConfig(filename)
|
||||
// retrieve config
|
||||
val conf = getConfig(cmd.configFile)
|
||||
|
||||
val prov = createProvInstance(cliCommand.target, remoteHostSetSudoWithoutPasswordRequired = true)
|
||||
// create
|
||||
val prov = createProvInstance(cmd.target, remoteHostSetSudoWithoutPasswordRequired = true)
|
||||
provision(prov, conf)
|
||||
|
||||
} catch (e: IllegalArgumentException) {
|
||||
println(
|
||||
"Error: File\u001b[31m $filename \u001b[0m was not found.\n" +
|
||||
"Pls copy file \u001B[31m WorkplaceConfigExample.yaml \u001B[0m to file \u001B[31m $filename \u001B[0m " +
|
||||
"Error: File\u001b[31m ${cmd.configFile} \u001b[0m was not found.\n" +
|
||||
"Pls copy file \u001B[31m WorkplaceConfigExample.yaml \u001B[0m to file \u001B[31m ${cmd.configFile} \u001B[0m " +
|
||||
"and change the content according to your needs.\n"
|
||||
)
|
||||
|
||||
|
|
|
@ -4,30 +4,9 @@ import org.domaindrivenarchitecture.provs.core.cli.TargetCliCommand
|
|||
|
||||
|
||||
class WorkplaceCliCommand(val configFile: String, val target: TargetCliCommand) {
|
||||
companion object {
|
||||
fun parseWorkplaceArguments(
|
||||
programName: String = "java -jar provs.jar",
|
||||
args: Array<String>
|
||||
): WorkplaceCliCommand {
|
||||
val parser = CliWorkplaceParser(programName)
|
||||
parser.parse(args)
|
||||
|
||||
return WorkplaceCliCommand(
|
||||
parser.configFileName ?: "WorkplaceConfig.yaml",
|
||||
TargetCliCommand(
|
||||
parser.localHost,
|
||||
parser.remoteHost,
|
||||
parser.userName,
|
||||
parser.sshWithPasswordPrompt,
|
||||
parser.sshWithGopassPath,
|
||||
parser.sshWithKey
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun isValid(): Boolean {
|
||||
return target.isValid()
|
||||
return configFile.isNotEmpty() && target.isValid()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,31 @@ package org.domaindrivenarchitecture.provs.workplace.application
|
|||
import kotlinx.cli.ArgType
|
||||
import kotlinx.cli.optional
|
||||
import org.domaindrivenarchitecture.provs.core.cli.CliTargetParser
|
||||
import org.domaindrivenarchitecture.provs.core.cli.TargetCliCommand
|
||||
|
||||
|
||||
open class CliWorkplaceParser(name: String) : CliTargetParser(name) {
|
||||
|
||||
class CliWorkplaceParser(name: String) : CliTargetParser(name) {
|
||||
val configFileName by argument(
|
||||
ArgType.String,
|
||||
"configFilename",
|
||||
"the filename containing the yaml config for the workplace"
|
||||
).optional()
|
||||
|
||||
|
||||
fun parseWorkplaceArguments(args: Array<String>): WorkplaceCliCommand {
|
||||
super.parse(args)
|
||||
|
||||
return WorkplaceCliCommand(
|
||||
configFileName ?: "WorkplaceConfig.yaml",
|
||||
TargetCliCommand(
|
||||
localHost,
|
||||
remoteHost,
|
||||
userName,
|
||||
sshWithPasswordPrompt,
|
||||
sshWithGopassPath,
|
||||
sshWithKey
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue