You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
provs/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParser.kt

65 lines
2.3 KiB
Kotlin

package org.domaindrivenarchitecture.provs.desktop.application
import kotlinx.cli.ArgType
import kotlinx.cli.Subcommand
import org.domaindrivenarchitecture.provs.configuration.application.CliTargetParser
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopCliCommand
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopSubmodule
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopType
open class CliArgumentsParser(name: String) : CliTargetParser(name) {
private val modules: List<DesktopSubcommand> = listOf(Basic(), Office(), Ide())
init {
subcommands(*modules.toTypedArray())
}
fun parseCommand(args: Array<String>): DesktopCliCommand {
super.parse(args)
val module = modules.first { it.parsed }
return DesktopCliCommand(
DesktopType.valueOf(module.name.uppercase()),
TargetCliCommand(
target,
passwordInteractive
),
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.Choice<DesktopSubmodule>(),
"only",
"o",
"provisions only parts ",
)
override fun execute() {
configFileName = cliConfigFileName?.let { ConfigFileName(it) }
parsed = true
submodules = if (only != null) listOf(only!!.name.lowercase()) else null
}
}
class Basic : DesktopSubcommand("basic", "basic desktop for a user")
class Office : DesktopSubcommand("office", "includes office software like Thunderbird, LibreOffice, etc")
class Ide : DesktopSubcommand("ide", "includes office software as well as ides like VSCode, etc")
}