diff --git a/build.gradle b/build.gradle index c78d23b..f9f789f 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ apply plugin: 'kotlinx-serialization' group = 'org.domaindrivenarchitecture.provs' -version = '0.8.32-SNAPSHOT' +version = '0.8.32' repositories { mavenCentral() diff --git a/docs/CliApplication.puml b/docs/CliApplication.puml index 324c54f..2fda107 100644 --- a/docs/CliApplication.puml +++ b/docs/CliApplication.puml @@ -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 diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/core/cli/CliUtils.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/core/cli/CliUtils.kt index 15917a0..66419e1 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/core/cli/CliUtils.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/core/cli/CliUtils.kt @@ -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 { diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/application/CliWorkplace.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/application/CliWorkplace.kt index 8287eb1..ab77a9e 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/application/CliWorkplace.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/application/CliWorkplace.kt @@ -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) { - 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" ) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/application/CliWorkplaceCommand.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/application/CliWorkplaceCommand.kt index e4def42..b6bca41 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/application/CliWorkplaceCommand.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/application/CliWorkplaceCommand.kt @@ -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 - ): 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() } } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/application/CliWorkplaceParser.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/application/CliWorkplaceParser.kt index 893e25f..becab73 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/application/CliWorkplaceParser.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/workplace/application/CliWorkplaceParser.kt @@ -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): WorkplaceCliCommand { + super.parse(args) + + return WorkplaceCliCommand( + configFileName ?: "WorkplaceConfig.yaml", + TargetCliCommand( + localHost, + remoteHost, + userName, + sshWithPasswordPrompt, + sshWithGopassPath, + sshWithKey + ) + ) + } } \ No newline at end of file