♻️ Better names and add printing methods

This commit is contained in:
Dan Jones 2024-11-04 15:20:09 -06:00
commit d5e7f601b6
4 changed files with 41 additions and 17 deletions

View file

@ -1,6 +1,8 @@
package convids
import (
"fmt"
"io"
"os"
fp "path/filepath"
"regexp"
@ -28,17 +30,23 @@ func ensureExtRe(c *Config) (err error) {
return
}
func WalkFiles(d *Data, stopOnError, silent bool, cb func(s *Show, path string) error) (err error) {
type ShowWalker func(show *Show, path string) error
type GroupPrinter func(name string, group Shows)
func WalkFiles(d *Data, stopOnError bool, gp GroupPrinter, cb ShowWalker) (err error) {
err = ensureExtRe(d.Config)
if err != nil {
return
}
if cb == nil {
cb = DryRun(os.Stdout)
}
var files []os.DirEntry
files, err = os.ReadDir(d.Config.Source)
if err != nil {
return
}
for s := range d.AllShows(silent) {
for s := range d.AllShows(gp) {
var found bool
for _, file := range files {
if file.IsDir() {
@ -62,3 +70,16 @@ func WalkFiles(d *Data, stopOnError, silent bool, cb func(s *Show, path string)
}
return nil
}
func DryRun(out io.Writer) ShowWalker {
return func(s *Show, path string) error {
fmt.Fprintf(out, "Saving %s to %s\n", path, s.Folder)
return nil
}
}
func PrintGroupName(out io.Writer) GroupPrinter {
return func(name string, group Shows) {
fmt.Fprintf(out, "Checking %s shows\n\n", name)
}
}