<commit_before>package main

import (
	"bytes"
	"flag"
	"fmt"
	stllog "log"
	"os"
	"strings"
	// "errors"
	// "io"

	"github.com/mguzelevich/go.log"

	"github.com/gojuno/junocfg"
)

var (
	checkTmpl bool
	merge     bool

	input  string
	output string
	tmpl   string
)

func init() {
	flag.BoolVar(&checkTmpl, "check-tmpl", false, "check tmpl")
	flag.BoolVar(&merge, "merge", false, "merge")

	flag.StringVar(&input, "i", "", "input")
	flag.StringVar(&input, "input", "", "input")
	flag.StringVar(&output, "o", "", "output")
	flag.StringVar(&output, "output", "", "output")
	flag.StringVar(&tmpl, "t", "", "template")
	flag.StringVar(&tmpl, "template", "", "template")
}

func checkFatal(errStr string, err error) {
	if err != nil {
		log.Stderr.Printf("ARGS: checkTmpl: [%v] merge: [%v] input: [%v] output: [%v] tmpl: [%v]\n",
			checkTmpl, merge,
			input, output, tmpl,
		)
		log.Stderr.Printf(errStr, err)
		os.Exit(1)
	}
}

func main() {
	// junocfg.Test()
	// os.Exit(1)

	flag.Parse()

	log.InitLoggers(&log.Logger{
		os.Stderr, // ioutil.Discard,
		os.Stderr, // ioutil.Discard,
		os.Stderr,
		os.Stderr,
		os.Stderr,
	})
	log.Stdout = stllog.New(os.Stdout, "", 0)
	log.Stderr = stllog.New(os.Stderr, "", 0)

	switch {
	case checkTmpl:
		// fmt.Fprintf(os.Stderr, "mode: check-tmpl\n")
		in, err := getInput(tmpl)
		log.Debug.Printf(in.dump())
		checkFatal("Error %v", in.err)
		_, err = junocfg.CheckTemplate(in.input[0])
		checkFatal("check tmpl error %v", err)
	case merge:
		// fmt.Fprintf(os.Stderr, "mode: merge\n")
		in, err := getInput(input)
		checkFatal("Error %v", err)
		out, err := junocfg.MergeYamls(in.input)
		// in.dump()
		checkFatal("Error %v", in.err)
		outResult(output, out)
	default:
		// fmt.Fprintf(os.Stderr, "mode: default\n")
		// default: generate config file from input + template
		if tmpl == "" {
			checkFatal("%v", fmt.Errorf("Field [template(-t|--tmpl)] required"))
		}

		tmplSrc, err := getInput(tmpl)
		checkFatal("Error %v", tmplSrc.err)

		template, err := junocfg.CheckTemplate(tmplSrc.input[0])
		checkFatal("check tmpl error %v", err)

		tmplSrc.dump()

		in, err := getInput(input)
		checkFatal("error %v", in.err)
		// in.dump()
		settingsData, err := junocfg.MergeYamls(in.input)
		checkFatal("error %v", err)<commit_msg>add verbose flag<commit_after>package main

import (
	"bytes"
	"flag"
	"fmt"
	stllog "log"
	"os"
	"strings"
	// "errors"
	// "io"

	"github.com/mguzelevich/go.log"

	"github.com/gojuno/junocfg"
)

var (
	checkTmpl bool
	merge     bool
	verbose   bool

	input  string
	output string
	tmpl   string
)

func init() {
	flag.BoolVar(&checkTmpl, "check-tmpl", false, "check tmpl")
	flag.BoolVar(&merge, "merge", false, "merge")
	flag.BoolVar(&verbose, "v", false, "verbose")

	flag.StringVar(&input, "i", "", "input")
	flag.StringVar(&input, "input", "", "input")
	flag.StringVar(&output, "o", "", "output")
	flag.StringVar(&output, "output", "", "output")
	flag.StringVar(&tmpl, "t", "", "template")
	flag.StringVar(&tmpl, "template", "", "template")
}

func checkFatal(errStr string, err error) {
	if err != nil {
		log.Stderr.Printf("ARGS: checkTmpl: [%v] merge: [%v] input: [%v] output: [%v] tmpl: [%v]\n",
			checkTmpl, merge,
			input, output, tmpl,
		)
		log.Stderr.Printf(errStr, err)
		os.Exit(1)
	}
}

func main() {
	// junocfg.Test()
	// os.Exit(1)

	flag.Parse()

	log.InitLoggers(&log.Logger{
		os.Stderr, // ioutil.Discard,
		os.Stderr, // ioutil.Discard,
		os.Stderr,
		os.Stderr,
		os.Stderr,
	})
	log.Stdout = stllog.New(os.Stdout, "", 0)
	log.Stderr = stllog.New(os.Stderr, "", 0)

	switch {
	case checkTmpl:
		in, err := getInput(tmpl)
		if verbose {
			log.Debug.Printf(in.dump())
		}
		checkFatal("Error %v", in.err)
		_, err = junocfg.CheckTemplate(in.input[0])
		checkFatal("check tmpl error %v", err)
	case merge:
		// fmt.Fprintf(os.Stderr, "mode: merge\n")
		in, err := getInput(input)
		checkFatal("Error %v", err)
		out, err := junocfg.MergeYamls(in.input)
		if verbose {
			log.Debug.Printf(in.dump())
		}
		checkFatal("Error %v", in.err)
		outResult(output, out)
	default:
		// fmt.Fprintf(os.Stderr, "mode: default\n")
		// default: generate config file from input + template
		if tmpl == "" {
			checkFatal("%v", fmt.Errorf("Field [template(-t|--tmpl)] required"))
		}

		tmplSrc, err := getInput(tmpl)
		checkFatal("Error %v", tmplSrc.err)

		template, err := junocfg.CheckTemplate(tmplSrc.input[0])
		checkFatal("check tmpl error %v", err)

		tmplSrc.dump()

		in, err := getInput(input)
		checkFatal("error %v", in.err)
		// in.dump()
		settingsData, err := junocfg.MergeYamls(in.input)
		checkFatal("error %v", err)
{'fraction_non_alphanumeric': 0.1950638666378004, 'fraction_numerical': 0.002597964927473479, 'mean_word_length': 3.8074921956295524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1634827', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1880, 'n_words': 378}