Correct server type check

Checking the serverType/subcommand from string input.
Before the check was done after parsing string input,
when an unknown server type was entered a "Too many
arguments!" error was issued due to the parser falsely
interpreting the input.
This commit is contained in:
erik 2022-08-17 15:32:38 +02:00
parent 81350db43d
commit 949fe0c1af

View file

@ -19,9 +19,15 @@ fun main(args: Array<String>) {
val checkedArgs = if (args.isEmpty()) arrayOf("-h") else args val checkedArgs = if (args.isEmpty()) arrayOf("-h") else args
// validate subcommand
if (!ServerType.values().any {it.name.lowercase() == args[0]}) {
println("Unknown serverType. Currently only k3s is accepted.")
exitProcess(1)
}
val cmd = CliArgumentsParser("provs-server.jar subcommand target").parseCommand(checkedArgs) val cmd = CliArgumentsParser("provs-server.jar subcommand target").parseCommand(checkedArgs)
// input validation // validate parsed arguments
if (!cmd.isValidTarget()) { if (!cmd.isValidTarget()) {
println("Remote or localhost not valid, please try -h for help.") println("Remote or localhost not valid, please try -h for help.")
exitProcess(1) exitProcess(1)