mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-10 16:42:51 +00:00
Reduce size of pgmconfig package
This commit is contained in:
@@ -5,18 +5,27 @@ package plugins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/pflag"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
)
|
||||
|
||||
const (
|
||||
PluginSymbol = "KustomizePlugin"
|
||||
BuiltinPluginPackage = "builtin"
|
||||
// Used with Go plugins.
|
||||
PluginSymbol = "KustomizePlugin"
|
||||
|
||||
// Location of builtins.
|
||||
BuiltinPluginPackage = "builtin"
|
||||
|
||||
// ApiVersion of builtins.
|
||||
BuiltinPluginApiVersion = BuiltinPluginPackage
|
||||
flagEnablePluginsName = "enable_alpha_plugins"
|
||||
flagEnablePluginsHelp = `enable plugins, an alpha feature.
|
||||
|
||||
flagEnablePluginsName = "enable_alpha_plugins"
|
||||
flagEnablePluginsHelp = `enable plugins, an alpha feature.
|
||||
See https://github.com/kubernetes-sigs/kustomize/blob/master/docs/plugins/README.md
|
||||
`
|
||||
flagErrorFmt = `
|
||||
@@ -36,11 +45,11 @@ func DefaultPluginConfig() *types.PluginConfig {
|
||||
return &types.PluginConfig{
|
||||
Enabled: false,
|
||||
DirectoryPath: filepath.Join(
|
||||
pgmconfig.ConfigRoot(), pgmconfig.PluginRoot),
|
||||
configRoot(), pgmconfig.PluginRoot),
|
||||
}
|
||||
}
|
||||
|
||||
func NotEnabledErr(name string) error {
|
||||
func notEnabledErr(name string) error {
|
||||
return fmt.Errorf(
|
||||
flagErrorFmt,
|
||||
name,
|
||||
@@ -53,3 +62,28 @@ func AddFlagEnablePlugins(set *pflag.FlagSet, v *bool) {
|
||||
v, flagEnablePluginsName,
|
||||
false, flagEnablePluginsHelp)
|
||||
}
|
||||
|
||||
// Use https://github.com/kirsle/configdir instead?
|
||||
func configRoot() string {
|
||||
dir := os.Getenv(pgmconfig.XdgConfigHome)
|
||||
if len(dir) == 0 {
|
||||
dir = filepath.Join(
|
||||
homeDir(), pgmconfig.DefaultConfigSubdir)
|
||||
}
|
||||
return filepath.Join(dir, pgmconfig.ProgramName)
|
||||
}
|
||||
|
||||
func homeDir() string {
|
||||
home := os.Getenv(homeEnv())
|
||||
if len(home) > 0 {
|
||||
return home
|
||||
}
|
||||
return "~"
|
||||
}
|
||||
|
||||
func homeEnv() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return "USERPROFILE"
|
||||
}
|
||||
return "HOME"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user