From a0a762b87eb9a7ad4b19b5b1b37869c511faf3a8 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Mon, 23 Mar 2020 12:01:08 +0100 Subject: [PATCH] fix: Fix default config path on Windows (#752) --- CHANGELOG.adoc | 4 ++++ pkg/kn/commands/types.go | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 2d2d1f074..c9563a0fc 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -30,6 +30,10 @@ | Fix plugin execution for Windows. | https://github.com/knative/client/pull/738[#738] +| 🐛 +| Fix default config path on Windows +| https://github.com/knative/client/pull/751[#751] + ## v0.13.0 (2020-03-11) [cols="1,10,3", options="header", width="100%"] diff --git a/pkg/kn/commands/types.go b/pkg/kn/commands/types.go index b7b723520..d7a840195 100644 --- a/pkg/kn/commands/types.go +++ b/pkg/kn/commands/types.go @@ -19,6 +19,7 @@ import ( "io" "os" "path/filepath" + "runtime" "k8s.io/client-go/dynamic" "k8s.io/client-go/rest" @@ -41,8 +42,8 @@ var CfgFile string // Cfg is Kn's configuration values var Cfg Config = Config{ - DefaultConfigDir: "~/.config/kn", - DefaultPluginDir: "~/.config/kn/plugins", + DefaultConfigDir: newDefaultConfigPath(""), + DefaultPluginDir: newDefaultConfigPath("plugins"), PluginsDir: "", LookupPlugins: newBoolP(false), } @@ -195,3 +196,11 @@ func newBoolP(b bool) *bool { aBool := b return &aBool } + +// Returns default config path based on target OS +func newDefaultConfigPath(subDir string) string { + if runtime.GOOS == "windows" { + return filepath.Join(os.Getenv("APPDATA"), "kn", subDir) + } + return filepath.Join("~", ".config", "kn", subDir) +}