Fix #115: cmk ignores the CLI profile arg when loading the cache file (#131)
* Fix problem 1 on issue #115
* Improvements
diff --git a/cmk.go b/cmk.go
index 74c8873..98d2027 100644
--- a/cmk.go
+++ b/cmk.go
@@ -86,6 +86,7 @@
if *profile != "" {
cfg.LoadProfile(*profile)
}
+ config.LoadCache(cfg)
if *apiKey != "" && *secretKey != "" {
request := cmd.NewRequest(nil, cfg, nil)
diff --git a/config/cache.go b/config/cache.go
index 34e021c..096582d 100644
--- a/config/cache.go
+++ b/config/cache.go
@@ -84,9 +84,7 @@
Debug("Trying to read API cache from:", cacheFile)
cache, err := ioutil.ReadFile(cacheFile)
if err != nil {
- if c.HasShell {
- fmt.Fprintf(os.Stderr, "Loaded in-built API cache. Failed to read API cache, please run 'sync'.\n")
- }
+ fmt.Fprintf(os.Stderr, "Loaded in-built API cache. Failed to read API cache, please run 'sync'.\n")
cache = []byte(preCache)
}
var data map[string]interface{}
diff --git a/config/config.go b/config/config.go
index 111df88..f9befed 100644
--- a/config/config.go
+++ b/config/config.go
@@ -200,7 +200,7 @@
cfg.ActiveProfile.Client = newHTTPClient(cfg)
}
-func reloadConfig(cfg *Config) *Config {
+func reloadConfig(cfg *Config, loadCache bool) *Config {
fileLock := flock.New(path.Join(getDefaultConfigDir(), "lock"))
err := fileLock.Lock()
if err != nil {
@@ -209,7 +209,9 @@
}
cfg = saveConfig(cfg)
fileLock.Unlock()
- LoadCache(cfg)
+ if loadCache {
+ LoadCache(cfg)
+ }
return cfg
}
@@ -360,7 +362,7 @@
Debug("UpdateConfig key:", key, " value:", value, " update:", update)
if update {
- reloadConfig(c)
+ reloadConfig(c, true)
}
}
@@ -376,7 +378,6 @@
os.Exit(1)
}
}
- cfg := reloadConfig(defaultConf)
- LoadCache(cfg)
+ cfg := reloadConfig(defaultConf, false)
return cfg
}