yaml files overriden via env

main
Bel LaPointe 2025-04-05 11:03:27 -06:00
parent d40a1f8fd4
commit 82a13aea65
1 changed files with 35 additions and 4 deletions

39
main.go
View File

@ -72,10 +72,9 @@ func Recursive(ctx context.Context) error {
p := path.Join(d, YamlFile)
if _, err := os.Stat(p); err != nil {
} else if err := func() error {
var y Yaml
b, _ := os.ReadFile(path.Join(d, YamlFile))
if err := yaml.Unmarshal(b, &y); err != nil {
return fmt.Errorf("%s: %w", p, err)
y, err := NewYaml(path.Join(d, YamlFile))
if err != nil {
return err
}
was, err := os.Getwd()
@ -280,3 +279,35 @@ func readDir(d string) ([]fs.DirEntry, error) {
}
return result, err
}
func NewYaml(p string) (Yaml, error) {
var y Yaml
b, _ := os.ReadFile(path.Join(d, YamlFile))
if err := yaml.Unmarshal(b, &y); err != nil {
return y, fmt.Errorf("%s: %w", p, err)
}
if v := os.Getenv("YAML_C_TITLE"); v != "" {
y.C.Title = v
}
if v := os.Getenv("YAML_C_SEASON"); v != "" {
y.C.Season = v
}
if v := os.Getenv("YAML_C_EPISODE"); v != "" {
y.C.Episode = v
}
if v := os.Getenv("YAML_O"); v != "" {
y.O = v
}
if v := os.Getenv("YAML_D"); v == "true" {
y.D = true
}
if v := os.Getenv("YAML_P"); v != "" {
y.P = strings.Split(v, ",")
}
return y, nil
}