[#4491] Implement support for XDG Base Dir Specs

Signed-off-by: Alexander Nesterenko <nestorf250@gmail.com>
pull/5166/head
Alexander Nesterenko 7 years ago
parent 62f144a9d8
commit 499269e181

@ -23,6 +23,7 @@ These dependencies are expressed as interfaces so that alternate implementations
package environment
import (
"github.com/casimir/xdg-go"
"os"
"path/filepath"
@ -32,8 +33,22 @@ import (
"k8s.io/helm/pkg/helm/helmpath"
)
// defaultHelmHome is the default HELM_HOME.
var defaultHelmHome = filepath.Join(homedir.HomeDir(), ".helm")
var oldDefaultHelmHome = filepath.Join(homedir.HomeDir(), ".helm")
var defaultHelmHome = filepath.Join(xdg.ConfigHome(), "helm")
// Get configuration home dir.
//
// Note: Temporal until all migrate to XDG Base Directory spec
func getDefaultConfigHome() string {
if _, err := os.Stat(defaultHelmHome); err != nil {
return defaultHelmHome
} else if _, err := os.Stat(oldDefaultHelmHome); err != nil {
return defaultHelmHome
}
// TODO: Write a warning to output
return oldDefaultHelmHome
}
// EnvSettings describes all of the environment settings.
type EnvSettings struct {
@ -51,7 +66,7 @@ type EnvSettings struct {
// AddFlags binds flags to the given flagset.
func (s *EnvSettings) AddFlags(fs *pflag.FlagSet) {
fs.StringVar((*string)(&s.Home), "home", defaultHelmHome, "location of your Helm config. Overrides $HELM_HOME")
fs.StringVar((*string)(&s.Home), "home", getDefaultConfigHome(), "location of your Helm config. Overrides $HELM_HOME")
fs.StringVarP(&s.Namespace, "namespace", "n", "", "namespace scope for this request")
fs.StringVar(&s.KubeConfig, "kubeconfig", "", "path to the kubeconfig file")
fs.StringVar(&s.KubeContext, "kube-context", "", "name of the kubeconfig context to use")

@ -40,8 +40,8 @@ func TestEnvSettings(t *testing.T) {
}{
{
name: "defaults",
home: defaultHelmHome,
plugins: helmpath.Home(defaultHelmHome).Plugins(),
home: oldDefaultHelmHome,
plugins: helmpath.Home(oldDefaultHelmHome).Plugins(),
ns: "",
},
{

Loading…
Cancel
Save