add GetOrDefault and related methods to Config#5022
Conversation
samcoe
left a comment
There was a problem hiding this comment.
This code looks good to me. What are next steps on making this operational? Seems like we will need to change configFunc() in default.go to return something other than a blank config when a config does not exist.
mislav
left a comment
There was a problem hiding this comment.
Looks good except that I don't understand why so many changes across the board? I had thought that only fetching keys that might have defaults will need to be switched to GetOrDefault— everything else can stay the same. But it looks like all Gets across the codebase were ported over?
|
@mislav good points. I did the bulk change because the exact behavior of |
|
@mislav those call sites are updated. |
| return c[fmt.Sprintf("%s:%s", host, key)], c["_source"], nil | ||
| } | ||
|
|
||
| func (c tinyConfig) Get(host, key string) (val string, err error) { |
There was a problem hiding this comment.
Was adding this method necessary? The interface that this struct aims to satisfy only has one method:
cli/pkg/cmd/auth/gitcredential/helper.go
Lines 16 to 18 in 227d0e0
Part of #3091
Part of #2711
This PR adds three new methods to our
Configtype:GetOrDefaultGetOrDefaultWithSourceDefaultand changes the behavior of
GetandGetWithSourceto now not automatically use a default value if no value has been set for a key.This change allows callers of the config system to know when a config value has been explicitly set by the user.
All existing invocations of
Getthat cared about a default have been replaced withGetOrDefaultto maintain the same functionality as prior to this PR and there are no intended end-user visible changes here.