Skip to content

Commit c4ea2b8

Browse files
authored
Fix #115: cmk ignores the CLI profile arg when loading the cache file (#131)
* Fix problem 1 on issue #115 * Improvements
1 parent 74698cd commit c4ea2b8

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

cmk.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func main() {
8686
if *profile != "" {
8787
cfg.LoadProfile(*profile)
8888
}
89+
config.LoadCache(cfg)
8990

9091
if *apiKey != "" && *secretKey != "" {
9192
request := cmd.NewRequest(nil, cfg, nil)

config/cache.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ func LoadCache(c *Config) interface{} {
8484
Debug("Trying to read API cache from:", cacheFile)
8585
cache, err := ioutil.ReadFile(cacheFile)
8686
if err != nil {
87-
if c.HasShell {
88-
fmt.Fprintf(os.Stderr, "Loaded in-built API cache. Failed to read API cache, please run 'sync'.\n")
89-
}
87+
fmt.Fprintf(os.Stderr, "Loaded in-built API cache. Failed to read API cache, please run 'sync'.\n")
9088
cache = []byte(preCache)
9189
}
9290
var data map[string]interface{}

config/config.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func setActiveProfile(cfg *Config, profile *ServerProfile) {
200200
cfg.ActiveProfile.Client = newHTTPClient(cfg)
201201
}
202202

203-
func reloadConfig(cfg *Config) *Config {
203+
func reloadConfig(cfg *Config, loadCache bool) *Config {
204204
fileLock := flock.New(path.Join(getDefaultConfigDir(), "lock"))
205205
err := fileLock.Lock()
206206
if err != nil {
@@ -209,7 +209,9 @@ func reloadConfig(cfg *Config) *Config {
209209
}
210210
cfg = saveConfig(cfg)
211211
fileLock.Unlock()
212-
LoadCache(cfg)
212+
if loadCache {
213+
LoadCache(cfg)
214+
}
213215
return cfg
214216
}
215217

@@ -360,7 +362,7 @@ func (c *Config) UpdateConfig(key string, value string, update bool) {
360362
Debug("UpdateConfig key:", key, " value:", value, " update:", update)
361363

362364
if update {
363-
reloadConfig(c)
365+
reloadConfig(c, true)
364366
}
365367
}
366368

@@ -376,7 +378,6 @@ func NewConfig(configFilePath *string) *Config {
376378
os.Exit(1)
377379
}
378380
}
379-
cfg := reloadConfig(defaultConf)
380-
LoadCache(cfg)
381+
cfg := reloadConfig(defaultConf, false)
381382
return cfg
382383
}

0 commit comments

Comments
 (0)