figure out the version

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-09 19:35:05 -06:00
parent abd9781d8a
commit be54390fcd
2 changed files with 39 additions and 1 deletions

View File

@ -76,7 +76,8 @@ func draw(rs *RepoStatus) {
rs.releaseVersion = rs.grid.NewButton("release version", func() {
lasttag := rs.lasttag.Get()
log.Warn("Should release version here", lasttag)
ver := normalizeVersion(lasttag)
log.Warn("Should release version here", lasttag, ver)
})
rs.releaseVersion.Disable()

37
unix.go
View File

@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"strings"
"regexp"
"go.wit.com/log"
)
@ -52,3 +53,39 @@ func listFiles(directory string) []string {
return files
}
/*
// string handling examples that might be helpful for normalizeInt()
isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString
for _, username := range []string{"userone", "user2", "user-three"} {
if !isAlpha(username) {
log.Log(GUI, "%q is not valid\n", username)
}
}
const alpha = "abcdefghijklmnopqrstuvwxyz"
func alphaOnly(s string) bool {
for _, char := range s {
if !strings.Contains(alpha, strings.ToLower(string(char))) {
return false
}
}
return true
}
*/
func normalizeVersion(s string) string {
// reg, err := regexp.Compile("[^a-zA-Z0-9]+")
parts := strings.Split(s, "-")
if len(parts) == 0 { return "" }
reg, err := regexp.Compile("[^0-9.]+")
if err != nil {
log.Log(WARN, "normalizeVersion() regexp.Compile() ERROR =", err)
return parts[0]
}
clean := reg.ReplaceAllString(parts[0], "")
log.Log(WARN, "normalizeVersion() s =", clean)
return clean
}