You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2018/09/10 06:11:56 UTC

[camel-k] 02/02: use os/user to determine user home

This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit c96e433cd3587e2df105f0362d32cc81dd263b4d
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Sep 10 07:51:48 2018 +0200

    use os/user to determine user home
---
 pkg/client/cmd/config.go | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/pkg/client/cmd/config.go b/pkg/client/cmd/config.go
index 93dbd7f..f7b347b 100644
--- a/pkg/client/cmd/config.go
+++ b/pkg/client/cmd/config.go
@@ -18,7 +18,7 @@ limitations under the License.
 package cmd
 
 import (
-	"os"
+	"os/user"
 	"path/filepath"
 
 	"github.com/operator-framework/operator-sdk/pkg/k8sclient"
@@ -29,7 +29,12 @@ import (
 func initKubeClient(cmd *cobra.Command) error {
 	kubeconfig := cmd.Flag("config").Value.String()
 	if kubeconfig == "" {
-		kubeconfig = filepath.Join(homeDir(), ".kube", "config")
+		usr, err := user.Current()
+		if err != nil {
+			return err
+		}
+
+		kubeconfig = filepath.Join(usr.HomeDir, ".kube", "config")
 	}
 
 	// use the current context in kubeconfig
@@ -41,10 +46,3 @@ func initKubeClient(cmd *cobra.Command) error {
 	k8sclient.CustomConfig = config
 	return nil
 }
-
-func homeDir() string {
-	if h := os.Getenv("HOME"); h != "" {
-		return h
-	}
-	return os.Getenv("USERPROFILE") // windows
-}