(opts plugingetter.ListInstallationsOptions, pluginIdentifier *addrs.Plugin, args *PluginsInstallArgs)
| 220 | } |
| 221 | |
| 222 | func (c *PluginsInstallCommand) InstallFromBinary(opts plugingetter.ListInstallationsOptions, pluginIdentifier *addrs.Plugin, args *PluginsInstallArgs) int { |
| 223 | pluginDir := opts.PluginDirectory |
| 224 | |
| 225 | var err error |
| 226 | |
| 227 | args.PluginPath, err = filepath.Abs(args.PluginPath) |
| 228 | if err != nil { |
| 229 | return writeDiags(c.Ui, nil, hcl.Diagnostics{&hcl.Diagnostic{ |
| 230 | Severity: hcl.DiagError, |
| 231 | Summary: "Failed to transform path", |
| 232 | Detail: fmt.Sprintf("Failed to transform the given path to an absolute one: %s", err), |
| 233 | }}) |
| 234 | } |
| 235 | |
| 236 | s, err := os.Stat(args.PluginPath) |
| 237 | if err != nil { |
| 238 | return writeDiags(c.Ui, nil, hcl.Diagnostics{&hcl.Diagnostic{ |
| 239 | Severity: hcl.DiagError, |
| 240 | Summary: "Unable to find plugin to promote", |
| 241 | Detail: fmt.Sprintf("The plugin %q failed to be opened because of an error: %s", args.PluginIdentifier, err), |
| 242 | }}) |
| 243 | } |
| 244 | |
| 245 | if s.IsDir() { |
| 246 | return writeDiags(c.Ui, nil, hcl.Diagnostics{&hcl.Diagnostic{ |
| 247 | Severity: hcl.DiagError, |
| 248 | Summary: "Plugin to promote cannot be a directory", |
| 249 | Detail: "The packer plugin promote command can only install binaries, not directories", |
| 250 | }}) |
| 251 | } |
| 252 | |
| 253 | describeCmd, err := exec.Command(args.PluginPath, "describe").Output() |
| 254 | if err != nil { |
| 255 | return writeDiags(c.Ui, nil, hcl.Diagnostics{&hcl.Diagnostic{ |
| 256 | Severity: hcl.DiagError, |
| 257 | Summary: "Failed to describe the plugin", |
| 258 | Detail: fmt.Sprintf("Packer failed to run %s describe: %s", args.PluginPath, err), |
| 259 | }}) |
| 260 | } |
| 261 | |
| 262 | var desc plugin.SetDescription |
| 263 | if err := json.Unmarshal(describeCmd, &desc); err != nil { |
| 264 | return writeDiags(c.Ui, nil, hcl.Diagnostics{&hcl.Diagnostic{ |
| 265 | Severity: hcl.DiagError, |
| 266 | Summary: "Failed to decode plugin describe info", |
| 267 | Detail: fmt.Sprintf("'%s describe' produced information that Packer couldn't decode: %s", args.PluginPath, err), |
| 268 | }}) |
| 269 | } |
| 270 | |
| 271 | semver, err := version.NewSemver(desc.Version) |
| 272 | if err != nil { |
| 273 | return writeDiags(c.Ui, nil, hcl.Diagnostics{&hcl.Diagnostic{ |
| 274 | Severity: hcl.DiagError, |
| 275 | Summary: "Invalid version", |
| 276 | Detail: fmt.Sprintf("Plugin's reported version (%q) is not semver-compatible: %s", desc.Version, err), |
| 277 | }}) |
| 278 | } |
| 279 | if semver.Prerelease() != "" && semver.Prerelease() != "dev" { |
no test coverage detected