2020-05-28 18:49:50 -04:00
|
|
|
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}}
|
2020-05-28 19:22:55 -04:00
|
|
|
}
|
|
|
|
`))
|
2020-05-28 18:49:50 -04:00
|
|
|
|
|
|
|
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()
|
2020-05-28 19:26:01 -04:00
|
|
|
allDeprecatedOpts = append(allDeprecatedOpts, deprecated...)
|
2020-05-28 18:49:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|