Skip to content

Commit 6e55e89

Browse files
committed
handle defaults at the Config level instead of ConfigMap
1 parent bba6343 commit 6e55e89

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

command/config_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package command
22

33
import (
44
"bytes"
5-
"fmt"
65
"testing"
76

87
"github.com/cli/cli/internal/config"
@@ -125,13 +124,12 @@ hosts:
125124
github.com:
126125
user: OWNER
127126
oauth_token: MUSTBEHIGHCUZIMATOKEN
127+
128128
editor: ed
129-
git_protocol: ssh
129+
git_protocol: ssh
130130
`
131131
initBlankContext(cfg, "OWNER/REPO", "master")
132132

133-
fmt.Println("IN TEST")
134-
135133
output, err := RunCommand(configGetCmd, "config get -hgithub.com git_protocol")
136134
if err != nil {
137135
t.Fatalf("error running command `config get -hgithub.com git_protocol`: %v", err)

internal/config/config_type.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,10 @@ type ConfigMap struct {
3535
}
3636

3737
func (cm *ConfigMap) GetStringValue(key string) (string, error) {
38-
// TODO defaults should not be handled at this level.
3938
_, valueNode, err := cm.FindEntry(key)
40-
var notFound *NotFoundError
41-
42-
if err != nil && errors.As(err, &notFound) {
43-
return defaultFor(key), nil
44-
} else if err != nil {
39+
if err != nil {
4540
return "", err
4641
}
47-
48-
if valueNode.Value == "" {
49-
return defaultFor(key), nil
50-
}
51-
5242
return valueNode.Value, nil
5343
}
5444

@@ -107,30 +97,38 @@ type fileConfig struct {
10797
}
10898

10999
func (c *fileConfig) Get(hostname, key string) (string, error) {
110-
value, err := c.GetStringValue(key)
111-
fmt.Println("!!!!!!", value)
112-
if err != nil {
113-
return "", err
114-
}
115-
116100
if hostname != "" {
117-
fmt.Println("hostname")
118101
hostCfg, err := c.configForHost(hostname)
119102
if err != nil {
120103
return "", err
121104
}
105+
122106
hostValue, err := hostCfg.GetStringValue(key)
123-
if err != nil {
107+
var notFound *NotFoundError
108+
109+
if err != nil && !errors.As(err, &notFound) {
124110
return "", err
125111
}
126112

127-
fmt.Println("WHY", hostValue)
128-
129113
if hostValue != "" {
130-
value = hostValue
114+
return hostValue, nil
131115
}
132116
}
133117

118+
value, err := c.GetStringValue(key)
119+
120+
var notFound *NotFoundError
121+
122+
if err != nil && errors.As(err, &notFound) {
123+
return defaultFor(key), nil
124+
} else if err != nil {
125+
return "", err
126+
}
127+
128+
if value == "" {
129+
return defaultFor(key), nil
130+
}
131+
134132
return value, nil
135133
}
136134

0 commit comments

Comments
 (0)