debug, dry, more env
parent
596865ede3
commit
e653c35275
40
main.go
40
main.go
|
|
@ -20,6 +20,16 @@ import (
|
|||
yaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var (
|
||||
Debug = os.Getenv("DEBUG") == "true"
|
||||
ConstTitle = os.Getenv("YAML_C_TITLE")
|
||||
ConstSeason = os.Getenv("YAML_C_SEASON")
|
||||
ConstEpisode = os.Getenv("YAML_C_EPISODE")
|
||||
ConstOutd = os.Getenv("YAML_O")
|
||||
Dry = os.Getenv("YAML_D") == "true" || os.Getenv("DRY") == "true"
|
||||
ConstPatterns = os.Getenv("YAML_P")
|
||||
)
|
||||
|
||||
type Yaml struct {
|
||||
C Fields
|
||||
O string
|
||||
|
|
@ -158,7 +168,7 @@ func RunWith(ctx context.Context, outd, ind string, patterns []string, overrides
|
|||
}
|
||||
for _, pattern := range patterns {
|
||||
for _, entry := range entries {
|
||||
if !entry.Type().IsRegular() {
|
||||
if !entry.Type().IsRegular() && !(Debug && Dry) {
|
||||
continue
|
||||
}
|
||||
if err := one(ctx, outd, path.Join(ind, entry.Name()), []string{pattern}, overrides, mvNLn); err != nil {
|
||||
|
|
@ -256,10 +266,16 @@ func DryMvNLn() func(string, string) error {
|
|||
outd := map[string]struct{}{}
|
||||
return func(outf, inf string) error {
|
||||
if _, err := os.Stat(outf); err == nil {
|
||||
if Debug {
|
||||
fmt.Fprintf(os.Stderr, "no mv %q\n %q\n", inf, outf)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, ok := outd[outf]; ok {
|
||||
if Debug {
|
||||
fmt.Fprintf(os.Stderr, "no mv %q\n %q\n", inf, outf)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
outd[outf] = struct{}{}
|
||||
|
|
@ -287,26 +303,26 @@ func NewYaml(p string) (Yaml, error) {
|
|||
return y, fmt.Errorf("%s: %w", p, err)
|
||||
}
|
||||
|
||||
if v := os.Getenv("YAML_C_TITLE"); v != "" {
|
||||
y.C.Title = v
|
||||
if ConstTitle != "" {
|
||||
y.C.Title = ConstTitle
|
||||
}
|
||||
if v := os.Getenv("YAML_C_SEASON"); v != "" {
|
||||
y.C.Season = v
|
||||
if ConstSeason != "" {
|
||||
y.C.Season = ConstSeason
|
||||
}
|
||||
if v := os.Getenv("YAML_C_EPISODE"); v != "" {
|
||||
y.C.Episode = v
|
||||
if ConstEpisode != "" {
|
||||
y.C.Episode = ConstEpisode
|
||||
}
|
||||
|
||||
if v := os.Getenv("YAML_O"); v != "" {
|
||||
y.O = v
|
||||
if ConstOutd != "" {
|
||||
y.O = ConstOutd
|
||||
}
|
||||
|
||||
if v := os.Getenv("YAML_D"); v == "true" {
|
||||
if Dry {
|
||||
y.D = true
|
||||
}
|
||||
|
||||
if v := os.Getenv("YAML_P"); v != "" {
|
||||
y.P = strings.Split(v, ",")
|
||||
if ConstPatterns != "" {
|
||||
y.P = strings.Split(ConstPatterns, ",")
|
||||
}
|
||||
|
||||
return y, nil
|
||||
|
|
|
|||
Loading…
Reference in New Issue