<commit_before>package main

import (
	"flag"
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"text/template"

	"github.com/hashicorp/packer/fix"
)

var deprecatedOptsTemplate = template.Must(template.New("deprecatedOptsTemplate").
	Parse(`//<!-- Code generated by generate-fixer-deprecations; DO NOT EDIT MANUALLY -->

package config

var DeprecatedOptions = []string{
{{- range .DeprecatedOpts}}
	"{{.}}",
{{- end}}
}
`))

type executeOpts struct {
	DeprecatedOpts []string
}

func main() {
	// Figure out location in directory structure
	args := flag.Args()
	if len(args) == 0 {
		// Default: process the file
		args = []string{os.Getenv("GOFILE")}
	}
	fname := args[0]

	absFilePath, err := filepath.Abs(fname)
	if err != nil {
		panic(err)
	}
	paths := strings.SplitAfter(absFilePath, "packer"+string(os.PathSeparator))
	packerDir := paths[0]

	// Load all deprecated options from all active fixers
	allDeprecatedOpts := []string{}
	for _, name := range fix.FixerOrder {
		fixer, ok := fix.Fixers[name]
		if !ok {
			panic("fixer not found: " + name)
		}

		deprecated := fixer.DeprecatedOptions()
		allDeprecatedOpts = append(allDeprecatedOpts, deprecated...)
	}

	deprecated_path := filepath.Join(packerDir, "helper", "config",
		"deprecated_options.go")

	outputFile, err := os.Create(deprecated_path)
	if err != nil {
		panic(err)
	}
	defer outputFile.Close()

	deprecated := &executeOpts{DeprecatedOpts: allDeprecatedOpts}
	err = deprecatedOptsTemplate.Execute(outputFile, deprecated)
	if err != nil {
		fmt.Printf("%v", err)
		os.Exit(1)
	}
}
<commit_msg>fix generator to work even in nested packer/packer dirs<commit_after>package main

import (
	"flag"
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"text/template"

	"github.com/hashicorp/packer/fix"
)

var deprecatedOptsTemplate = template.Must(template.New("deprecatedOptsTemplate").
	Parse(`//<!-- Code generated by generate-fixer-deprecations; DO NOT EDIT MANUALLY -->

package config

var DeprecatedOptions = []string{
{{- range .DeprecatedOpts}}
	"{{.}}",
{{- end}}
}
`))

type executeOpts struct {
	DeprecatedOpts []string
}

func main() {
	// Figure out location in directory structure
	args := flag.Args()
	if len(args) == 0 {
		// Default: process the file
		args = []string{os.Getenv("GOFILE")}
	}
	fname := args[0]

	absFilePath, err := filepath.Abs(fname)
	if err != nil {
		panic(err)
	}
	paths := strings.Split(absFilePath, "cmd"+string(os.PathSeparator)+
		"generate-fixer-deprecations"+string(os.PathSeparator)+"main.go")
	packerDir := paths[0]

	// Load all deprecated options from all active fixers
	allDeprecatedOpts := []string{}
	for _, name := range fix.FixerOrder {
		fixer, ok := fix.Fixers[name]
		if !ok {
			panic("fixer not found: " + name)
		}

		deprecated := fixer.DeprecatedOptions()
		allDeprecatedOpts = append(allDeprecatedOpts, deprecated...)
	}

	deprecated_path := filepath.Join(packerDir, "helper", "config",
		"deprecated_options.go")

	outputFile, err := os.Create(deprecated_path)
	if err != nil {
		panic(err)
	}
	defer outputFile.Close()

	deprecated := &executeOpts{DeprecatedOpts: allDeprecatedOpts}
	err = deprecatedOptsTemplate.Execute(outputFile, deprecated)
	if err != nil {
		fmt.Printf("%v", err)
		os.Exit(1)
	}
}

{'fraction_non_alphanumeric': 0.15145872129112353, 'fraction_numerical': 0.002482929857231533, 'mean_word_length': 4.380634390651085, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4924737', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1126, 'n_words': 253}