inits/cmd/dkl-apply-config/main.go

51 lines
1014 B
Go
Raw Normal View History

2018-07-06 08:07:37 +00:00
package main
import (
"flag"
"os"
2018-07-08 05:48:22 +00:00
"strings"
2018-07-06 08:07:37 +00:00
"novit.nc/direktil/inits/pkg/apply"
"novit.nc/direktil/pkg/config"
dlog "novit.nc/direktil/pkg/log"
)
var (
log = dlog.Get("dkl-apply-config")
)
func main() {
2018-07-06 23:12:08 +00:00
configPath := flag.String("config", "config.yaml", "config to load (\"-\" for stdin)")
2018-07-06 08:07:37 +00:00
doFiles := flag.Bool("files", false, "apply files")
2018-07-08 05:48:22 +00:00
filesFilters := flag.String("files-filters", "*", "comma-separated filters to select files to apply")
2018-07-06 08:07:37 +00:00
flag.Parse()
log.SetConsole(os.Stderr)
2018-07-06 23:12:08 +00:00
var (
cfg *config.Config
err error
)
if *configPath == "-" {
2018-07-07 03:27:13 +00:00
log.Print("loading config from stdin")
2018-07-06 23:12:08 +00:00
cfg, err = config.Read(os.Stdin)
} else {
2018-07-07 03:27:13 +00:00
log.Print("loading config from ", *configPath)
2018-07-06 23:12:08 +00:00
cfg, err = config.Load(*configPath)
}
2018-07-06 08:07:37 +00:00
if err != nil {
log.Print("failed to load config: ", err)
}
if *doFiles {
2018-07-08 05:48:22 +00:00
filters := strings.Split(*filesFilters, ",")
if err = apply.Files(cfg, log, filters...); err != nil {
2018-07-07 03:42:59 +00:00
log.Taint(dlog.Fatal, "failed to apply files: ", err)
os.Exit(1)
2018-07-07 03:27:13 +00:00
}
2018-07-06 08:07:37 +00:00
}
}