(ctx context.Context, cla *ValidateArgs)
| 49 | } |
| 50 | |
| 51 | func (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 |
no test coverage detected