From dea0eb2d4457376a3d4d30b531c322c09784d204 Mon Sep 17 00:00:00 2001 From: Rob Loranger Date: Thu, 8 Aug 2019 09:30:56 -0700 Subject: [PATCH] wf check for config when auth required this adds a check for configured defaults during the command pre check when authentication is required. using the values found if both are present and only if both flags are ommitted. --- cmd/wf/commands.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmd/wf/commands.go b/cmd/wf/commands.go index 3b64bc1..4ffabca 100644 --- a/cmd/wf/commands.go +++ b/cmd/wf/commands.go @@ -31,6 +31,24 @@ func requireAuth(f cli.ActionFunc, action string) cli.ActionFunc { } else if err != nil { return cli.NewExitError(fmt.Sprintf("Failed to check for logged in users: %v", err), 1) } + } else if !c.GlobalIsSet("host") && !c.GlobalIsSet("user") { + // check for global configured pair host/user + cfg, err := config.LoadConfig(config.UserDataDir(c.App.ExtraInfo()["configDir"])) + if err != nil { + return cli.NewExitError(fmt.Sprintf("Failed to load config from file: %v", err), 1) + // set flags if found + } + // set flags if both were found in config + if cfg.Default.Host != "" && cfg.Default.User != "" { + err = c.GlobalSet("host", cfg.Default.Host) + if err != nil { + return cli.NewExitError(fmt.Sprintf("Failed to set host from global config: %v", err), 1) + } + err = c.GlobalSet("user", cfg.Default.User) + if err != nil { + return cli.NewExitError(fmt.Sprintf("Failed to set user from global config: %v", err), 1) + } + } } u, err := config.LoadUser(c) if err != nil {