MCPcopy
hub / github.com/hashicorp/packer / main

Function main

cmd/generate-fixer-deprecations/main.go:34–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32}
33
34func main() {
35 // Figure out location in directory structure
36 args := flag.Args()
37 if len(args) == 0 {
38 // Default: process the file
39 args = []string{os.Getenv("GOFILE")}
40 }
41 fname := args[0]
42
43 absFilePath, err := filepath.Abs(fname)
44 if err != nil {
45 panic(err)
46 }
47 paths := strings.Split(absFilePath, "cmd"+string(os.PathSeparator)+
48 "generate-fixer-deprecations"+string(os.PathSeparator)+"main.go")
49 packerDir := paths[0]
50
51 // Load all deprecated options from all active fixers
52 allDeprecatedOpts := map[string][]string{}
53 for _, name := range fix.FixerOrder {
54 fixer, ok := fix.Fixers[name]
55 if !ok {
56 panic("fixer not found: " + name)
57 }
58
59 deprecated := fixer.DeprecatedOptions()
60 for k, v := range deprecated {
61 if allDeprecatedOpts[k] == nil {
62 allDeprecatedOpts[k] = v
63 } else {
64 allDeprecatedOpts[k] = append(allDeprecatedOpts[k], v...)
65 }
66 }
67 }
68
69 deprecated_path := filepath.Join(packerDir, "packer-plugin-sdk", "template",
70 "config", "deprecated_options.go")
71
72 buf := bytes.Buffer{}
73
74 // execute template into buffer
75 deprecated := &executeOpts{DeprecatedOpts: allDeprecatedOpts}
76 err = deprecatedOptsTemplate.Execute(&buf, deprecated)
77 if err != nil {
78 panic(err)
79 }
80 // we've written unformatted go code to the file. now we have to format it.
81 out, err := format.Source(buf.Bytes())
82 if err != nil {
83 panic(err)
84 }
85
86 outputFile, err := os.Create(deprecated_path)
87 if err != nil {
88 panic(err)
89 }
90 _, err = outputFile.Write(out)
91 defer outputFile.Close()

Callers

nothing calls this directly

Calls 6

ExitMethod · 0.80
DeprecatedOptionsMethod · 0.65
SourceMethod · 0.65
WriteMethod · 0.65
ExecuteMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…