🚧 WalkFiles

This commit is contained in:
Dan Jones 2024-10-23 21:24:10 -05:00
commit 19206a9bf5
6 changed files with 157 additions and 16 deletions

View file

@ -1,22 +1,61 @@
package convids
import (
"errors"
"fmt"
"iter"
"regexp"
"slices"
"strings"
)
func (s Shows) All() iter.Seq[Show] {
return slices.Values(s)
var ErrNoName = errors.New("missing name")
func (s *Show) Match(path string) (bool, error) {
if s.Pattern != "" {
return s.matchRegexp(path)
}
if s.Name == "" {
return false, ErrNoName
}
return strings.HasPrefix(path, s.Name), nil
}
func (d Data) AllShows(silent bool) iter.Seq[Show] {
return func(yield func(Show) bool) {
func (s *Show) matchRegexp(path string) (f bool, err error) {
if s.re == nil {
p := s.Pattern
if !strings.HasPrefix(p, "^") {
p = "^" + p
}
s.re, err = regexp.Compile(p)
if err != nil {
return
}
}
return s.re.MatchString(path), nil
}
func (ss *Shows) All() iter.Seq[*Show] {
return slices.Values(*ss)
}
func (d *Data) AllShows(silent bool) iter.Seq[*Show] {
return func(yield func(*Show) bool) {
if d.Config == nil {
return
}
for _, show := range d.Config.Shows {
sh := (*d.Shows)[show]
if sh == nil || len(*sh) < 1 {
continue
}
if !silent {
fmt.Println("\nChecking", show, "shows\n")
}
for s := range d.Shows[show].All() {
for s := range sh.All() {
if s == nil {
continue
}
if !yield(s) {
return
}