Compare commits

..

No commits in common. "5fb296c17696a7a4c951726e42352e55f174694d" and "d55c680ec4f18cb95fdb6c445cd15042de39474e" have entirely different histories.

6 changed files with 35 additions and 111 deletions

View file

@ -1,8 +1,7 @@
version: "2"
linters: linters:
enable: enable:
- errcheck - errcheck
- gosimple
- govet - govet
- ineffassign - ineffassign
- staticcheck - staticcheck
@ -23,17 +22,18 @@ linters:
- gosec - gosec
- perfsprint - perfsprint
- testifylint - testifylint
settings:
testifylint: linters-settings:
enable-all: true testifylint:
disable: enable-all: true
- require-error disable:
gocognit: - require-error
min-complexity: 16 gocognit:
gocyclo: min-complexity: 16
min-complexity: 15 gocyclo:
gocritic: min-complexity: 15
enable-all: true gocritic:
settings: enable-all: true
hugeParam: settings:
sizeThreshold: 255 hugeParam:
sizeThreshold: 255

View file

@ -16,7 +16,6 @@ func main() {
m, err := ic.NewMerger(os.Args[1:]) m, err := ic.NewMerger(os.Args[1:])
e.HandleErr(err) e.HandleErr(err)
//nolint:errcheck // I don't care about this
defer m.Close() defer m.Close()
err = m.ParseFiles() err = m.ParseFiles()

View file

@ -1,8 +1,6 @@
package convids package convids
import ( import (
"bufio"
"cmp"
"context" "context"
"errors" "errors"
"fmt" "fmt"
@ -18,16 +16,7 @@ import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
type ShowWalker func(show *Show, path string) error
type GroupPrinter func(name string, group Shows)
var ErrNoFiles = errors.New("no files processed")
var ErrSkipped = errors.New("skipped")
var ErrMissingConfig = errors.New("missing config")
var ErrMissingShows = errors.New("missing shows")
func NewData(path string) (*Data, error) { func NewData(path string) (*Data, error) {
//nolint:gosec // I don't care if this is user input
f, err := os.Open(path) f, err := os.Open(path)
if err != nil { if err != nil {
return nil, err return nil, err
@ -35,17 +24,7 @@ func NewData(path string) (*Data, error) {
ydec := yaml.NewDecoder(f) ydec := yaml.NewDecoder(f)
var data Data var data Data
err = ydec.Decode(&data) err = ydec.Decode(&data)
if err != nil { return &data, err
return nil, err
}
if data.Config == nil {
return nil, ErrMissingConfig
}
if data.Shows == nil || len(*(data.Shows)) == 0 {
return nil, ErrMissingShows
}
return &data, nil
} }
func ensureExtRe(c *Config) (err error) { func ensureExtRe(c *Config) (err error) {
@ -56,6 +35,12 @@ func ensureExtRe(c *Config) (err error) {
return return
} }
type ShowWalker func(show *Show, path string) error
type GroupPrinter func(name string, group Shows)
var ErrNoFiles = errors.New("no files processed")
var ErrSkipped = errors.New("skipped")
type processInput struct { type processInput struct {
file os.DirEntry file os.DirEntry
source string source string
@ -167,8 +152,8 @@ func WalkFiles(d *Data, stopOnError bool, gp GroupPrinter, cb ShowWalker) (err e
func DryRun(out io.Writer) ShowWalker { func DryRun(out io.Writer) ShowWalker {
return func(s *Show, path string) error { return func(s *Show, path string) error {
_, err := fmt.Fprintf(out, "Saving %s to %s\n", path, s.Folder) fmt.Fprintf(out, "Saving %s to %s\n", path, s.Folder)
return cmp.Or(err, ErrSkipped) return ErrSkipped
} }
} }
@ -178,53 +163,18 @@ func GetShow(ctx context.Context) ShowWalker {
func GetShowWithIO(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer) ShowWalker { func GetShowWithIO(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer) ShowWalker {
return func(s *Show, path string) error { return func(s *Show, path string) error {
if !s.Url { //nolint:gosec // I don't care if this is using user input
return runGetShowsCmd(ctx, s.Folder, path, stdin, stdout, stderr) cmd := exec.CommandContext(ctx, "get-shows", s.Folder, path)
} cmd.Stdin = stdin
cmd.Stdout = stdout
orig := path cmd.Stderr = stderr
//nolint:gosec // I don't care if this is user input return cmd.Run()
readFile, err := os.Open(orig)
if err != nil {
return err
}
//nolint:errcheck // I don't care
defer readFile.Close()
fileScan := bufio.NewScanner(readFile)
fileScan.Split(bufio.ScanLines)
for fileScan.Scan() {
path = fileScan.Text()
err := runGetShowsCmd(ctx, s.Folder, path, stdin, stdout, stderr)
if err != nil {
return err
}
}
if s.Backup != "" {
err = os.Rename(orig, fp.Join(s.Backup, fp.Base(orig)))
if err != nil {
_, _ = fmt.Fprintf(stdout, "Moved %s to %s\n", orig, s.Backup)
}
} else {
err = os.Remove(orig)
}
return err
} }
}
func runGetShowsCmd(ctx context.Context, folder, path string, stdin io.Reader, stdout, stderr io.Writer) error {
//nolint:gosec // I don't care if this is using user input
cmd := exec.CommandContext(ctx, "get-shows", folder, path)
cmd.Stdin = stdin
cmd.Stdout = stdout
cmd.Stderr = stderr
return cmd.Run()
} }
func PrintGroupName(out io.Writer) GroupPrinter { func PrintGroupName(out io.Writer) GroupPrinter {
return func(name string, group Shows) { return func(name string, group Shows) {
_, _ = fmt.Fprintf(out, "Checking %s shows\n\n", name) fmt.Fprintf(out, "Checking %s shows\n\n", name)
} }
} }

View file

@ -25,8 +25,6 @@ type Show struct {
Pattern string Pattern string
Name string Name string
Anime bool Anime bool
Url bool
Backup string
Sources []string Sources []string
re *regexp.Regexp re *regexp.Regexp

View file

@ -7,7 +7,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"os" "os"
"slices"
_ "github.com/glebarez/go-sqlite" _ "github.com/glebarez/go-sqlite"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
@ -197,35 +196,13 @@ func (m *Merger) getRecipes(ctx context.Context, items []Item) (err error) {
if recs, found = rm[items[idx].Id]; found { if recs, found = rm[items[idx].Id]; found {
items[idx].Recipes = make([][]int32, 0, len(recs)) items[idx].Recipes = make([][]int32, 0, len(recs))
for _, rec := range recs { for _, rec := range recs {
addRecs(&(items[idx].Recipes), rec) items[idx].Recipes = append(items[idx].Recipes, rec)
} }
} }
} }
return return
} }
func addRecs(recs *[][]int32, rec []int32) {
slices.Sort(rec)
if !slices.ContainsFunc(*recs, recSorter(rec)) {
*recs = append(*recs, rec)
}
}
func recSorter(rec []int32) func([]int32) bool {
return func(v []int32) bool {
slices.Sort(v)
if !(len(v) == len(rec)) {
return false
}
for idx, i := range v {
if !(i == rec[idx]) {
return false
}
}
return true
}
}
func (m *Merger) Merge(ctx context.Context) (g Game, err error) { func (m *Merger) Merge(ctx context.Context) (g Game, err error) {
if err = m.getGameDetails(ctx, &g); err != nil { if err = m.getGameDetails(ctx, &g); err != nil {
return return

View file

@ -50,11 +50,11 @@ func (a *App) run(ctx context.Context) error {
} }
func (a *App) runInLoop(ctx context.Context) error { func (a *App) runInLoop(ctx context.Context) error {
_, _ = fmt.Fprintln(a.stdout, "Looping") fmt.Fprintln(a.stdout, "Looping")
var err error var err error
for err == nil { for err == nil {
err = a.run(ctx) err = a.run(ctx)
_, _ = fmt.Fprintln(a.stdout, err) fmt.Fprintln(a.stdout, err)
} }
return err return err
} }