🎉 Start project

This commit is contained in:
Dan Jones 2024-10-23 15:56:56 -05:00
commit c711ed6567
7 changed files with 119 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
build/

42
cmd/convids/main.go Normal file
View file

@ -0,0 +1,42 @@
package main
import (
"fmt"
"os"
"codeberg.org/danjones000/utils/convids"
"codeberg.org/danjones000/utils/internal/cli"
"github.com/spf13/pflag"
"gopkg.in/yaml.v3"
)
const dataPath = "shows.yml"
func main() {
loop := pflag.BoolP("loop", "l", false, "Loop")
help := pflag.BoolP("help", "h", false, "Get Help")
pflag.Parse()
if *help {
pflag.Usage()
os.Exit(2)
}
if *loop {
fmt.Println("looping")
}
f, err := os.Open(dataPath)
cli.HandleErr(err)
ydec := yaml.NewDecoder(f)
var data convids.Data
err = ydec.Decode(&data)
cli.HandleErr(err)
fmt.Printf("Data: %+v\n", data)
for s := range data.AllShows(false) {
fmt.Printf("Show: %+v\n", s)
}
}

26
convids/methods.go Normal file
View file

@ -0,0 +1,26 @@
package convids
import (
"fmt"
"iter"
"slices"
)
func (s Shows) All() iter.Seq[Show] {
return slices.Values(s)
}
func (d Data) AllShows(silent bool) iter.Seq[Show] {
return func(yield func(Show) bool) {
for _, show := range d.Config.Shows {
if !silent {
fmt.Println("\nChecking", show, "shows\n")
}
for s := range d.Shows[show].All() {
if !yield(s) {
return
}
}
}
}
}

23
convids/models.go Normal file
View file

@ -0,0 +1,23 @@
package convids
type Data struct {
Config Config
Shows ShowMap
}
type Config struct {
Source string
Extensions []string
Shows []string
}
type ShowMap map[string]Shows
type Shows []Show
type Show struct {
Folder string
Pattern string
Name string
Anime bool
}

8
go.mod Normal file
View file

@ -0,0 +1,8 @@
module codeberg.org/danjones000/utils
go 1.23.1
require (
github.com/spf13/pflag v1.0.5
gopkg.in/yaml.v3 v3.0.1
)

6
go.sum Normal file
View file

@ -0,0 +1,6 @@
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

13
internal/cli/cli.go Normal file
View file

@ -0,0 +1,13 @@
package cli
import (
"fmt"
"os"
)
func HandleErr(err error) {
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}