mirror of
https://github.com/hashicorp/packer.git
synced 2026-02-26 03:12:01 -05:00
* Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl. * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package command
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"log"
|
|
"runtime"
|
|
"strings"
|
|
|
|
plugingetter "github.com/hashicorp/packer/packer/plugin-getter"
|
|
)
|
|
|
|
type PluginsInstalledCommand struct {
|
|
Meta
|
|
}
|
|
|
|
func (c *PluginsInstalledCommand) Synopsis() string {
|
|
return "List all installed Packer plugin binaries"
|
|
}
|
|
|
|
func (c *PluginsInstalledCommand) Help() string {
|
|
helpText := `
|
|
Usage: packer plugins installed
|
|
|
|
This command lists all installed plugin binaries that match with the current
|
|
OS and architecture. Packer's API version will be ignored.
|
|
|
|
`
|
|
|
|
return strings.TrimSpace(helpText)
|
|
}
|
|
|
|
func (c *PluginsInstalledCommand) Run(args []string) int {
|
|
ctx, cleanup := handleTermInterrupt(c.Ui)
|
|
defer cleanup()
|
|
|
|
return c.RunContext(ctx)
|
|
}
|
|
|
|
func (c *PluginsInstalledCommand) RunContext(buildCtx context.Context) int {
|
|
|
|
opts := plugingetter.ListInstallationsOptions{
|
|
FromFolders: c.Meta.CoreConfig.Components.PluginConfig.KnownPluginFolders,
|
|
BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{
|
|
OS: runtime.GOOS,
|
|
ARCH: runtime.GOARCH,
|
|
Checksummers: []plugingetter.Checksummer{
|
|
{Type: "sha256", Hash: sha256.New()},
|
|
},
|
|
},
|
|
}
|
|
|
|
if runtime.GOOS == "windows" && opts.Ext == "" {
|
|
opts.BinaryInstallationOptions.Ext = ".exe"
|
|
}
|
|
|
|
log.Printf("[TRACE] init: %#v", opts)
|
|
|
|
// a plugin requirement that matches them all
|
|
allPlugins := plugingetter.Requirement{
|
|
Accessor: "",
|
|
VersionConstraints: nil,
|
|
Identifier: nil,
|
|
Implicit: false,
|
|
}
|
|
|
|
installations, err := allPlugins.ListInstallations(opts)
|
|
if err != nil {
|
|
c.Ui.Error(err.Error())
|
|
return 1
|
|
}
|
|
|
|
for _, installation := range installations {
|
|
c.Ui.Message(installation.BinaryPath)
|
|
}
|
|
|
|
return 0
|
|
}
|