fix: Fix default config path on Windows (#752)

This commit is contained in:
David Simansky 2020-03-23 12:01:08 +01:00 committed by GitHub
parent 5e73d8dad3
commit a0a762b87e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -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%"]

View File

@ -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)
}