boot v2 progress: disks, ssh, success...

This commit is contained in:
Mikaël Cluseau
2022-03-08 11:45:56 +01:00
parent 8e86579004
commit 8506f8807d
38 changed files with 1767 additions and 113 deletions

39
regexp.go Normal file
View File

@ -0,0 +1,39 @@
package main
import (
"log"
"regexp"
)
func regexpSelectN(n int, regexps []string, names []string) (matches []string) {
if n <= 0 {
matches = make([]string, 0)
} else {
matches = make([]string, 0, n)
}
res := make([]*regexp.Regexp, 0, len(regexps))
for _, reStr := range regexps {
re, err := regexp.Compile(reStr)
if err != nil {
log.Printf("warning: invalid regexp ignored: %q: %v", reStr, err)
continue
}
res = append(res, re)
}
namesLoop:
for _, name := range names {
if len(matches) == n {
break
}
for _, re := range res {
if re.MatchString(name) {
matches = append(matches, name)
continue namesLoop
}
}
}
return
}