49 lines
656 B
Go
49 lines
656 B
Go
|
package zet
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"regexp"
|
||
|
"sort"
|
||
|
"strconv"
|
||
|
|
||
|
"code.oliverdavies.uk/opdavies/cmd-zet/internal/git"
|
||
|
)
|
||
|
|
||
|
func GetAllZets() []int {
|
||
|
zets, err := git.ExecGitCommand("ls-files")
|
||
|
|
||
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
}
|
||
|
|
||
|
re := regexp.MustCompile(`[0-9]+`)
|
||
|
matches := re.FindAllString(zets, -1)
|
||
|
|
||
|
sort.Strings(matches)
|
||
|
|
||
|
ids := make(map[int]struct{})
|
||
|
for _, id := range matches {
|
||
|
num, err := strconv.Atoi(id)
|
||
|
|
||
|
if err == nil {
|
||
|
ids[num] = struct{}{}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var sorted []int
|
||
|
for num := range ids {
|
||
|
sorted = append(sorted, num)
|
||
|
}
|
||
|
|
||
|
sort.Ints(sorted)
|
||
|
|
||
|
return sorted
|
||
|
}
|
||
|
|
||
|
func GetLatestZet() int {
|
||
|
z := GetAllZets()
|
||
|
|
||
|
return z[len(z)-1]
|
||
|
}
|
||
|
|