tui/validators/mc_version.go

47 lines
728 B
Go
Raw Permalink Normal View History

2024-07-04 21:22:54 +02:00
package validators
import (
"fmt"
)
func McVersion(versions []string) TextInputValidator {
return TextInputMCVersion{
versions: versions,
}
}
type TextInputMCVersion struct {
versions []string
}
func (d TextInputMCVersion) Notice() string {
var versionString string
for index, version := range d.versions {
if index == (len(d.versions) - 1) {
versionString = versionString + version
} else {
versionString = versionString + version + ", "
}
}
return fmt.Sprintf("Available Versions: %s", versionString)
}
func (d TextInputMCVersion) ValidationFunc(input string) bool {
isFound := false
for _, ver := range d.versions {
if ver == input {
isFound = true
break
}
}
return isFound
}