package main

import (
	"bytes"
	"flag"
	"fmt"
	"os"

	"gopkg.in/yaml.v3"
	config "novit.tech/direktil/pkg/bootstrapconfig"
)

func main() {
	flag.Parse()

	for _, arg := range flag.Args() {
		fmt.Println("testing", arg)

		cfgBytes, err := os.ReadFile(arg)
		fail(err)

		cfg := config.Config{}

		dec := yaml.NewDecoder(bytes.NewBuffer(cfgBytes))
		dec.KnownFields(true)

		err = dec.Decode(&cfg)
		fail(err)
	}
}

func fail(err error) {
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		os.Exit(1)
	}
}
