From 55dcf5e79c9b30ff40d3234cd07e95e2a33cb719 Mon Sep 17 00:00:00 2001 From: Rob Loranger Date: Fri, 2 Aug 2019 10:58:36 -0700 Subject: [PATCH] CurrentUser only use global when needed by needed: when host flag was supplied, matches that configured and a user is set in config as well. they should be a pair. --- config/user.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/config/user.go b/config/user.go index adbfa64..f62e3d7 100644 --- a/config/user.go +++ b/config/user.go @@ -147,10 +147,17 @@ func CurrentUser(c *cli.Context) (string, error) { } if cfg.Default.User == "" { // Load app-level config - cfg, err = LoadConfig(UserDataDir(c.App.ExtraInfo()["configDir"])) + globalCFG, err := LoadConfig(UserDataDir(c.App.ExtraInfo()["configDir"])) if err != nil { return "", err } + // only user global defaults when both are set and hosts match + if globalCFG.Default.User != "" && + globalCFG.Default.Host != "" && + c.GlobalIsSet("host") && + globalCFG.Default.Host == c.GlobalString("host") { + cfg = globalCFG + } } // Use user flag value