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

Method RunContext

command/validate.go:51–109  ·  view source on GitHub ↗
(ctx context.Context, cla *ValidateArgs)

Source from the content-addressed store, hash-verified

49}
50
51func (c *ValidateCommand) RunContext(ctx context.Context, cla *ValidateArgs) int {
52 // Set the release only flag if specified as argument
53 //
54 // This deactivates the capacity for Packer to load development binaries.
55 c.CoreConfig.Components.PluginConfig.ReleasesOnly = cla.ReleaseOnly
56
57 // By default we want to inform users of undeclared variables when validating but not during build time.
58 cla.MetaArgs.WarnOnUndeclaredVar = true
59 if cla.NoWarnUndeclaredVar {
60 cla.MetaArgs.WarnOnUndeclaredVar = false
61 }
62
63 packerStarter, ret := c.GetConfig(&cla.MetaArgs)
64 if ret != 0 {
65 return 1
66 }
67
68 // If we're only checking syntax, then we're done already
69 if cla.SyntaxOnly {
70 c.Ui.Say("Syntax-only check passed. Everything looks okay.")
71 return 0
72 }
73
74 diags := packerStarter.DetectPluginBinaries()
75 ret = writeDiags(c.Ui, nil, diags)
76 if ret != 0 {
77 return ret
78 }
79
80 if packer.PackerUseProto {
81 log.Printf("[TRACE] Using protobuf for communication with plugins")
82 }
83
84 diags = packerStarter.Initialize(packer.InitializeOptions{
85 SkipDatasourcesExecution: !cla.EvaluateDatasources,
86 UseSequential: cla.UseSequential,
87 })
88 ret = writeDiags(c.Ui, nil, diags)
89 if ret != 0 {
90 return ret
91 }
92
93 _, diags = packerStarter.GetBuilds(packer.GetBuildsOptions{
94 Only: cla.Only,
95 Except: cla.Except,
96 })
97
98 fixerDiags := packerStarter.FixConfig(packer.FixConfigOptions{
99 Mode: packer.Diff,
100 })
101 diags = append(diags, fixerDiags...)
102
103 ret = writeDiags(c.Ui, nil, diags)
104 if ret == 0 {
105 c.Ui.Say("The configuration is valid.")
106 }
107
108 return ret

Callers 1

RunMethod · 0.95

Calls 7

writeDiagsFunction · 0.85
GetConfigMethod · 0.80
DetectPluginBinariesMethod · 0.65
InitializeMethod · 0.65
GetBuildsMethod · 0.65
FixConfigMethod · 0.65
SayMethod · 0.45

Tested by

no test coverage detected