From e153db05efb03cdb6e025ea84c49ee5a5addcd7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Kochen?= Date: Sun, 16 May 2021 10:46:02 +0200 Subject: [PATCH] Use os.UserHomeDir --- cmd/cluster_kubeconfig.go | 7 +++---- cmd/config.go | 10 ++-------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/cmd/cluster_kubeconfig.go b/cmd/cluster_kubeconfig.go index 54cc0c95..fab288ae 100644 --- a/cmd/cluster_kubeconfig.go +++ b/cmd/cluster_kubeconfig.go @@ -6,7 +6,7 @@ import ( "io/ioutil" "log" "os" - "os/user" + "path/filepath" "strings" "github.com/spf13/cobra" @@ -52,9 +52,8 @@ Example 4: hetzner-kube cluster kubeconfig -n my-cluster -p > my-conf.yaml # pri } else { fmt.Println("create file") - usr, _ := user.Current() - dir := usr.HomeDir - path := fmt.Sprintf("%s/.kube", dir) + dir, _ := os.UserHomeDir() + path := filepath.Join(dir, ".kube") if _, err := os.Stat(path); os.IsNotExist(err) { os.MkdirAll(path, 0755) diff --git a/cmd/config.go b/cmd/config.go index 9ad50009..e063b948 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -8,7 +8,6 @@ import ( "io/ioutil" "log" "os" - "os/user" "path/filepath" "github.com/hetznercloud/hcloud-go/hcloud" @@ -29,13 +28,8 @@ type AppSSHClient struct { // NewAppConfig creates a new AppConfig struct using the locally saved configuration file. If no local // configuration file is found a new config will be created. func NewAppConfig(debug bool) AppConfig { - usr, err := user.Current() - if err != nil { - return AppConfig{} - } - if usr.HomeDir != "" { - DefaultConfigPath = filepath.Join(usr.HomeDir, ".hetzner-kube") - } + dir, _ := os.UserHomeDir() + DefaultConfigPath = filepath.Join(dir, ".hetzner-kube") appConf := AppConfig{ Context: context.Background(),