X Tutup
Skip to content

Commit cabf0b1

Browse files
committed
populate initial config
1 parent 85b4183 commit cabf0b1

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

context/context.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ func (c *fsContext) Config() (config.Config, error) {
165165
if c.config == nil {
166166
cfg, err := config.ParseDefaultConfig()
167167
if errors.Is(err, os.ErrNotExist) {
168-
cfg = config.NewBlankConfig()
168+
cfg, err = config.InitDefaultConfig()
169+
if err != nil {
170+
return nil, fmt.Errorf("could not create default config: %w", err)
171+
}
169172
} else if err != nil {
170173
return nil, err
171174
}

internal/config/config_type.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,63 @@ func NewConfig(root *yaml.Node) Config {
122122
}
123123
}
124124

125+
func InitDefaultConfig() (Config, error) {
126+
cfg := NewConfig(&yaml.Node{
127+
Kind: yaml.DocumentNode,
128+
Content: []*yaml.Node{
129+
{
130+
Kind: yaml.MappingNode,
131+
Content: []*yaml.Node{
132+
{
133+
HeadComment: "What protocol to use when performing git operations. Supported values: ssh, https",
134+
Kind: yaml.ScalarNode,
135+
Value: "git_protocol",
136+
},
137+
{
138+
Kind: yaml.ScalarNode,
139+
Value: "https",
140+
},
141+
{
142+
HeadComment: "What editor gh should run when creating issues, pull requests, etc. If blank, will refer to environment.",
143+
Kind: yaml.ScalarNode,
144+
Value: "editor",
145+
},
146+
{
147+
Kind: yaml.ScalarNode,
148+
Value: "",
149+
},
150+
{
151+
HeadComment: "Aliases allow you to create nicknames for gh commands",
152+
Kind: yaml.ScalarNode,
153+
Value: "aliases",
154+
},
155+
{
156+
Kind: yaml.MappingNode,
157+
Content: []*yaml.Node{
158+
{
159+
Kind: yaml.ScalarNode,
160+
Value: "co",
161+
},
162+
{
163+
Kind: yaml.ScalarNode,
164+
Value: "pr checkout",
165+
},
166+
},
167+
},
168+
},
169+
},
170+
},
171+
})
172+
173+
err := cfg.Write()
174+
if err != nil {
175+
return nil, err
176+
}
177+
178+
return cfg, nil
179+
180+
}
181+
125182
func NewBlankConfig() Config {
126183
return NewConfig(&yaml.Node{
127184
Kind: yaml.DocumentNode,

0 commit comments

Comments
 (0)
X Tutup