Browse Source

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.
pull/36/head
Rob Loranger 4 years ago
parent
commit
dea0eb2d44
No known key found for this signature in database GPG Key ID: D6F1633A4F0903B8
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      cmd/wf/commands.go

+ 18
- 0
cmd/wf/commands.go View File

@@ -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 {


Loading…
Cancel
Save