<commit_before>package main

import (
	"log"

	"github.com/brettlangdon/realm"
	"github.com/codegangsta/cli"
)

func main() {
	// Setup our CLI app
	var app *cli.App = cli.NewApp()
	app.Name = "realm"
	app.Usage = "A simple non-recursive DNS server"
	app.Version = "0.1.0"
	app.Author = "<NAME>"
	app.Email = "<EMAIL>"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "zone, z",
			EnvVar: "REALM_ZONE",
			Usage:  "location to DNS zone file [required]",
		},
		cli.StringFlag{
			Name:   "bind, b",
			EnvVar: "REALM_BIND",
			Value:  ":53",
			Usage:  "'[<host>]:<port>' to bind too",
		},
	}

	// This action is called for all commands
	app.Action = func(c *cli.Context) {
		// Ensure that a zone filename was provided
		var filename string = c.String("zone")
		if filename == "" {
			log.Fatal("must supply zone file via \"--zone\" flag or \"REALM_ZONE\" environment variable")
		}

		// Load and parse the zone file
		var zone *realm.Zone
		var err error
		log.Printf("parsing zone file \"%s\"\n", filename)
		zone, err = realm.ParseZone(filename)
		if err != nil {
			log.Fatal(err)
		}

		// Create and start the server
		var bind string = c.String("bind")
		log.Printf("starting the server on \"%s\"\n", bind)
		var server *realm.Server = realm.NewServer(bind, zone)
		log.Fatal(server.ListenAndServe())
	}

	// Parse command arguments and run `app.Action`
	app.RunAndExitOnError()
}
<commit_msg>use go-arg and registry<commit_after>package main

import (
	"log"
	"os"

	"github.com/alexflint/go-arg"
	"github.com/brettlangdon/realm"
)

var args struct {
	Zones []string `arg:"--zone,positional,help:DNS zone files to serve from this server"`
	Bind  string   `arg:"help:[<host>]:<port> to bind too"`
}

func main() {
	args.Bind = ":53"
	argParser := arg.MustParse(&args)

	if len(args.Zones) == 0 {
		log.Println("must supply at least 1 zone file to serve")
		argParser.WriteUsage(os.Stderr)
		os.Exit(1)
	}

	var registry *realm.Registry
	registry = realm.NewRegistry()

	for _, filename := range args.Zones {
		// Load and parse the zone file
		var zone *realm.Zone
		var err error
		log.Printf("parsing zone file \"%s\"\n", filename)
		zone, err = realm.ParseZone(filename)
		if err != nil {
			log.Fatal(err)
		}
		registry.AddZone(zone)
	}

	// Create and start the server
	log.Printf("starting the server on \"%s\"\n", args.Bind)
	var server *realm.Server = realm.NewServer(args.Bind, registry)
	log.Fatal(server.ListenAndServe())
}

{'fraction_non_alphanumeric': 0.15293637846655792, 'fraction_numerical': 0.004078303425774877, 'mean_word_length': 3.411870503597122, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, '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': '6492443', 'n_tokens_mistral': 970, 'n_tokens_neox': 898, 'n_words': 244}