Files
Packer-Cn/packer/plugin_folders.go
hashicorp-copywrite[bot] b7df3ca36f [COMPLIANCE] Add Copyright and License Headers (#12254)
Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-03-02 15:37:05 -05:00

39 lines
864 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package packer
import (
"log"
"os"
"path/filepath"
"strings"
"github.com/hashicorp/packer-plugin-sdk/pathing"
)
// PluginFolders returns the list of known plugin folders based on system.
func PluginFolders(dirs ...string) []string {
res := []string{}
if path, err := os.Executable(); err != nil {
log.Printf("[ERR] Error finding executable: %v", err)
} else {
res = append(res, path)
}
res = append(res, dirs...)
if cd, err := pathing.ConfigDir(); err != nil {
log.Printf("[ERR] Error loading config directory: %v", err)
} else {
res = append(res, filepath.Join(cd, "plugins"))
}
if packerPluginPath := os.Getenv("PACKER_PLUGIN_PATH"); packerPluginPath != "" {
res = append(res, strings.Split(packerPluginPath, string(os.PathListSeparator))...)
}
return res
}