Refactor
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
a3202aaff3
commit
948872b933
7 changed files with 206 additions and 150 deletions
48
internal/zet/get.go
Normal file
48
internal/zet/get.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
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]
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue