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

Method RunContext

command/plugins_required.go:72–126  ·  view source on GitHub ↗
(buildCtx context.Context, cla *PluginsRequiredArgs)

Source from the content-addressed store, hash-verified

70}
71
72func (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(`
119No plugins requirement found, make sure you reference a Packer config
120containing a packer.required_plugins block. See
121https://www.packer.io/docs/templates/hcl_templates/blocks/packer
122for more info.`)
123 }
124
125 return 0
126}

Callers 1

RunMethod · 0.95

Calls 7

writeDiagsFunction · 0.85
GetConfigMethod · 0.80
ListInstallationsMethod · 0.80
PluginRequirementsMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.65
MessageMethod · 0.45

Tested by

no test coverage detected