(buildCtx context.Context, cla *PluginsRequiredArgs)
| 70 | } |
| 71 | |
| 72 | func (c *PluginsRequiredCommand) RunContext(buildCtx context.Context, cla *PluginsRequiredArgs) int { |
| 73 | |
| 74 | packerStarter, ret := c.GetConfig(&cla.MetaArgs) |
| 75 | if ret != 0 { |
| 76 | return ret |
| 77 | } |
| 78 | |
| 79 | // Get plugins requirements |
| 80 | reqs, diags := packerStarter.PluginRequirements() |
| 81 | ret = writeDiags(c.Ui, nil, diags) |
| 82 | if ret != 0 { |
| 83 | return ret |
| 84 | } |
| 85 | |
| 86 | ext := "" |
| 87 | if runtime.GOOS == "windows" { |
| 88 | ext = ".exe" |
| 89 | } |
| 90 | opts := plugingetter.ListInstallationsOptions{ |
| 91 | PluginDirectory: c.Meta.CoreConfig.Components.PluginConfig.PluginDirectory, |
| 92 | BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{ |
| 93 | OS: runtime.GOOS, |
| 94 | ARCH: runtime.GOARCH, |
| 95 | Ext: ext, |
| 96 | APIVersionMajor: pluginsdk.APIVersionMajor, |
| 97 | APIVersionMinor: pluginsdk.APIVersionMinor, |
| 98 | Checksummers: []plugingetter.Checksummer{ |
| 99 | {Type: "sha256", Hash: sha256.New()}, |
| 100 | }, |
| 101 | }, |
| 102 | } |
| 103 | |
| 104 | for _, pluginRequirement := range reqs { |
| 105 | s := fmt.Sprintf("%s %s %q", pluginRequirement.Accessor, pluginRequirement.Identifier.String(), pluginRequirement.VersionConstraints.String()) |
| 106 | installs, err := pluginRequirement.ListInstallations(opts) |
| 107 | if err != nil { |
| 108 | c.Ui.Error(err.Error()) |
| 109 | return 1 |
| 110 | } |
| 111 | for _, install := range installs { |
| 112 | s += fmt.Sprintf(" %s", install.BinaryPath) |
| 113 | } |
| 114 | c.Ui.Message(s) |
| 115 | } |
| 116 | |
| 117 | if len(reqs) == 0 { |
| 118 | c.Ui.Message(` |
| 119 | No plugins requirement found, make sure you reference a Packer config |
| 120 | containing a packer.required_plugins block. See |
| 121 | https://www.packer.io/docs/templates/hcl_templates/blocks/packer |
| 122 | for more info.`) |
| 123 | } |
| 124 | |
| 125 | return 0 |
| 126 | } |
no test coverage detected