From 52ba99ebabd0f77257698326d0896591fae4809e Mon Sep 17 00:00:00 2001 From: William Martin Date: Wed, 18 Oct 2023 16:59:39 +0200 Subject: [PATCH] Update AuthConfig to use default fn --- internal/config/config.go | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index a413baa64..a9a421bd4 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -58,7 +58,7 @@ func (c *cfg) GetOrDefault(hostname, key string) (string, error) { return val, err } - if val, ok := def(key); ok { + if val, ok := defaultFor(key); ok { return val, nil } @@ -85,7 +85,7 @@ func (c *cfg) Authentication() *AuthConfig { return &AuthConfig{cfg: c.cfg} } -func def(key string) (string, bool) { +func defaultFor(key string) (string, bool) { for _, co := range configOptions { if co.Key == key { return co.DefaultValue, true @@ -94,24 +94,6 @@ func def(key string) (string, bool) { return "", false } -func defaultFor(key string) string { - for _, co := range configOptions { - if co.Key == key { - return co.DefaultValue - } - } - return "" -} - -func defaultExists(key string) bool { - for _, co := range configOptions { - if co.Key == key { - return true - } - } - return false -} - // AuthConfig is used for interacting with some persistent configuration for gh, // with knowledge on how to access encrypted storage when neccesarry. // Behavior is scoped to authentication specific tasks. @@ -185,7 +167,12 @@ func (c *AuthConfig) GitProtocol(hostname string) (string, error) { if err == nil { return val, err } - return defaultFor(key), nil + + if val, ok := defaultFor(key); ok { + return val, nil + } + + return "", nil } func (c *AuthConfig) Hosts() []string {