go run ./ i to init conf file
This commit is contained in:
31
main.go
31
main.go
@@ -7,6 +7,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -19,6 +20,15 @@ import (
|
|||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Yaml struct {
|
||||||
|
C Fields
|
||||||
|
O string
|
||||||
|
D bool
|
||||||
|
P []string
|
||||||
|
}
|
||||||
|
|
||||||
|
const YamlFile = ".show-ingestion.yaml"
|
||||||
|
|
||||||
type Fields struct {
|
type Fields struct {
|
||||||
Title string
|
Title string
|
||||||
Season string
|
Season string
|
||||||
@@ -34,28 +44,33 @@ func main() {
|
|||||||
foo := Main
|
foo := Main
|
||||||
if len(os.Args) == 2 && os.Args[1] == "r" {
|
if len(os.Args) == 2 && os.Args[1] == "r" {
|
||||||
foo = Recursive
|
foo = Recursive
|
||||||
|
} else if len(os.Args) == 2 && os.Args[1] == "i" {
|
||||||
|
foo = Stage
|
||||||
}
|
}
|
||||||
if err := foo(ctx); err != nil {
|
if err := foo(ctx); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Stage(ctx context.Context) error {
|
||||||
|
if _, err := os.Stat(YamlFile); err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
b, _ := yaml.Marshal(Yaml{D: true})
|
||||||
|
return ioutil.WriteFile(YamlFile, b, os.ModePerm)
|
||||||
|
}
|
||||||
|
|
||||||
func Recursive(ctx context.Context) error {
|
func Recursive(ctx context.Context) error {
|
||||||
q := []string{"./"}
|
q := []string{"./"}
|
||||||
for len(q) > 0 {
|
for len(q) > 0 {
|
||||||
d := q[0]
|
d := q[0]
|
||||||
q = q[1:]
|
q = q[1:]
|
||||||
|
|
||||||
p := path.Join(d, ".show-ingestion.yaml")
|
p := path.Join(d, YamlFile)
|
||||||
if _, err := os.Stat(p); err != nil {
|
if _, err := os.Stat(p); err != nil {
|
||||||
} else if err := func() error {
|
} else if err := func() error {
|
||||||
var y struct {
|
var y Yaml
|
||||||
C Fields
|
b, _ := os.ReadFile(path.Join(d, YamlFile))
|
||||||
O string
|
|
||||||
D bool
|
|
||||||
P []string
|
|
||||||
}
|
|
||||||
b, _ := os.ReadFile(path.Join(d, ".show-ingestion.yaml"))
|
|
||||||
if err := yaml.Unmarshal(b, &y); err != nil {
|
if err := yaml.Unmarshal(b, &y); err != nil {
|
||||||
return fmt.Errorf("%s: %w", p, err)
|
return fmt.Errorf("%s: %w", p, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user