<commit_before>package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"io/ioutil"
	"os"
	"sort"
)

var (
	inFile  string
	outFile string
)

func init() {
	flag.StringVar(&inFile, "f", "", "The file to read from to generate parameters")
	flag.StringVar(&outFile, "o", "", "Optional: Specify a file name to write out parameters")
}

func main() {
	flag.Parse()

	if inFile == "" {
		fmt.Fprintln(os.Stderr, "Missing required argument -f")
	}

	m := make(map[string]interface{})
	data, err := ioutil.ReadFile(inFile)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(-1)
	}
	err = json.Unmarshal(data, &m)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(-1)
	}

	if _, ok := m["Parameters"]; !ok {
		fmt.Fprintln(os.Stderr, "Parameters not found in file")
		os.Exit(-1)
	}

	params := m["Parameters"].(map[string]interface{})

	keys := make([]string, 0)

	for k := range params {
		keys = append(keys, k)
	}

	sort.Strings(keys)

	s := "[\n"

	for i, k := range keys {
		s += fmt.Sprintf(`	{
		"ParameterKey": "%s",
		"ParameterValue": ""
	}`, k)
		if i != len(keys)-1 {
			s += `,
`
		}
	}

	s += "\n]"

	if outFile != "" {
		err = ioutil.WriteFile(outFile, []byte(data), 0644)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
		}<commit_msg>fixes incorrect variable when writing to file<commit_after>package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"io/ioutil"
	"os"
	"sort"
)

var (
	inFile  string
	outFile string
)

func init() {
	flag.StringVar(&inFile, "f", "", "The file to read from to generate parameters")
	flag.StringVar(&outFile, "o", "", "Optional: Specify a file name to write out parameters")
}

func main() {
	flag.Parse()

	if inFile == "" {
		fmt.Fprintln(os.Stderr, "Missing required argument -f")
	}

	m := make(map[string]interface{})
	data, err := ioutil.ReadFile(inFile)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(-1)
	}
	err = json.Unmarshal(data, &m)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(-1)
	}

	if _, ok := m["Parameters"]; !ok {
		fmt.Fprintln(os.Stderr, "Parameters not found in file")
		os.Exit(-1)
	}

	params := m["Parameters"].(map[string]interface{})

	keys := make([]string, 0)

	for k := range params {
		keys = append(keys, k)
	}

	sort.Strings(keys)

	s := "[\n"

	for i, k := range keys {
		s += fmt.Sprintf(`	{
		"ParameterKey": "%s",
		"ParameterValue": ""
	}`, k)
		if i != len(keys)-1 {
			s += `,
`
		}
	}

	s += "\n]"

	if outFile != "" {
		err = ioutil.WriteFile(outFile, []byte(s), 0644)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
		}
{'fraction_non_alphanumeric': 0.19301686936053356, 'fraction_numerical': 0.007061592781482934, 'mean_word_length': 3.314720812182741, 'pattern_counts': {'":': 4, '<': 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': '3530654', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1022, 'n_words': 248}