<commit_before>package main

import (
	"fmt"

	"k8s.io/dns/cmd/node-cache/app"

	"flag"
	"net"
	"os"
	"strconv"
	"strings"

	corednsmain "github.com/coredns/coredns/coremain"
	clog "github.com/coredns/coredns/plugin/pkg/log"

	// blank imports to make sure the plugin code is pulled in from vendor when building node-cache image
	"github.com/caddyserver/caddy"
	_ "github.com/coredns/coredns/plugin/bind"
	_ "github.com/coredns/coredns/plugin/cache"
	_ "github.com/coredns/coredns/plugin/debug"
	_ "github.com/coredns/coredns/plugin/errors"
	_ "github.com/coredns/coredns/plugin/forward"
	_ "github.com/coredns/coredns/plugin/health"
	_ "github.com/coredns/coredns/plugin/loadbalance"
	_ "github.com/coredns/coredns/plugin/log"
	_ "github.com/coredns/coredns/plugin/loop"
	_ "github.com/coredns/coredns/plugin/metrics"
	_ "github.com/coredns/coredns/plugin/pprof"
	_ "github.com/coredns/coredns/plugin/reload"
	_ "github.com/coredns/coredns/plugin/whoami"
)

var cache *app.CacheApp

func init() {
	params, err := parseAndValidateFlags()
	if err != nil {
		clog.Fatalf("Error parsing flags - %s, Exiting", err)
	}
	cache, err = app.NewCacheApp(params)
	if err != nil {
		clog.Fatalf("Failed to obtain CacheApp instance, err %v", err)
	}
	cache.Init()
	if !params.SkipTeardown {
		caddy.OnProcessExit = append(caddy.OnProcessExit, func() { cache.TeardownNetworking() })
	}
}

func parseAndValidateFlags() (*app.ConfigParams, error) {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
		fmt.Fprintf(os.Stderr, "Runs CoreDNS v%s as a nodelocal cache listening on the specified ip:port\n\n", corednsmain.CoreVersion)
		flag.PrintDefaults()
	}

	params := &app.ConfigParams{LocalPort: "53"}<commit_msg>Include template plugin in node-cache.<commit_after>package main

import (
	"fmt"

	"k8s.io/dns/cmd/node-cache/app"

	"flag"
	"net"
	"os"
	"strconv"
	"strings"

	corednsmain "github.com/coredns/coredns/coremain"
	clog "github.com/coredns/coredns/plugin/pkg/log"

	// blank imports to make sure the plugin code is pulled in from vendor when building node-cache image
	"github.com/caddyserver/caddy"
	_ "github.com/coredns/coredns/plugin/bind"
	_ "github.com/coredns/coredns/plugin/cache"
	_ "github.com/coredns/coredns/plugin/debug"
	_ "github.com/coredns/coredns/plugin/errors"
	_ "github.com/coredns/coredns/plugin/forward"
	_ "github.com/coredns/coredns/plugin/health"
	_ "github.com/coredns/coredns/plugin/loadbalance"
	_ "github.com/coredns/coredns/plugin/log"
	_ "github.com/coredns/coredns/plugin/loop"
	_ "github.com/coredns/coredns/plugin/metrics"
	_ "github.com/coredns/coredns/plugin/pprof"
	_ "github.com/coredns/coredns/plugin/reload"
	_ "github.com/coredns/coredns/plugin/template"
	_ "github.com/coredns/coredns/plugin/whoami"
)

var cache *app.CacheApp

func init() {
	params, err := parseAndValidateFlags()
	if err != nil {
		clog.Fatalf("Error parsing flags - %s, Exiting", err)
	}
	cache, err = app.NewCacheApp(params)
	if err != nil {
		clog.Fatalf("Failed to obtain CacheApp instance, err %v", err)
	}
	cache.Init()
	if !params.SkipTeardown {
		caddy.OnProcessExit = append(caddy.OnProcessExit, func() { cache.TeardownNetworking() })
	}
}

func parseAndValidateFlags() (*app.ConfigParams, error) {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
		fmt.Fprintf(os.Stderr, "Runs CoreDNS v%s as a nodelocal cache listening on the specified ip:port\n\n", corednsmain.CoreVersion)
		flag.PrintDefaults()
	}

	params := &app.ConfigParams{LocalPort: "53"}
{'fraction_non_alphanumeric': 0.1456145330684076, 'fraction_numerical': 0.0022707919386886176, 'mean_word_length': 4.463565891472868, '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': '3911376', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1414, 'n_words': 228}