tui/validators/mc_version.go

47 lines
728 B
Go
Raw Normal View History

2024-11-01 21:04:01 +01: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
}