add GetOrDefault functionality to config

This commit is contained in:
nate smith 2022-01-11 14:56:58 -06:00
parent eaa64df801
commit 562f1b3d0d
33 changed files with 116 additions and 58 deletions

View file

@ -14,7 +14,7 @@ import (
const tokenUser = "x-access-token"
type config interface {
GetWithSource(string, string) (string, string, error)
GetOrDefaultWithSource(string, string) (string, string, error)
}
type CredentialOptions struct {
@ -101,11 +101,11 @@ func helperRun(opts *CredentialOptions) error {
}
var gotUser string
gotToken, source, _ := cfg.GetWithSource(wants["host"], "oauth_token")
gotToken, source, _ := cfg.GetOrDefaultWithSource(wants["host"], "oauth_token")
if strings.HasSuffix(source, "_TOKEN") {
gotUser = tokenUser
} else {
gotUser, _, _ = cfg.GetWithSource(wants["host"], "user")
gotUser, _, _ = cfg.GetOrDefaultWithSource(wants["host"], "user")
}
if gotUser == "" || gotToken == "" {