Skip to content

Commit

Permalink
populate initial config
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed Jun 10, 2020
1 parent 85b4183 commit cabf0b1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
5 changes: 4 additions & 1 deletion context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ func (c *fsContext) Config() (config.Config, error) {
if c.config == nil {
cfg, err := config.ParseDefaultConfig()
if errors.Is(err, os.ErrNotExist) {
cfg = config.NewBlankConfig()
cfg, err = config.InitDefaultConfig()
if err != nil {
return nil, fmt.Errorf("could not create default config: %w", err)
}
} else if err != nil {
return nil, err
}
Expand Down
57 changes: 57 additions & 0 deletions internal/config/config_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,63 @@ func NewConfig(root *yaml.Node) Config {
}
}

func InitDefaultConfig() (Config, error) {
cfg := NewConfig(&yaml.Node{
Kind: yaml.DocumentNode,
Content: []*yaml.Node{
{
Kind: yaml.MappingNode,
Content: []*yaml.Node{
{
HeadComment: "What protocol to use when performing git operations. Supported values: ssh, https",
Kind: yaml.ScalarNode,
Value: "git_protocol",
},
{
Kind: yaml.ScalarNode,
Value: "https",
},
{
HeadComment: "What editor gh should run when creating issues, pull requests, etc. If blank, will refer to environment.",
Kind: yaml.ScalarNode,
Value: "editor",
},
{
Kind: yaml.ScalarNode,
Value: "",
},
{
HeadComment: "Aliases allow you to create nicknames for gh commands",
Kind: yaml.ScalarNode,
Value: "aliases",
},
{
Kind: yaml.MappingNode,
Content: []*yaml.Node{
{
Kind: yaml.ScalarNode,
Value: "co",
},
{
Kind: yaml.ScalarNode,
Value: "pr checkout",
},
},
},
},
},
},
})

err := cfg.Write()
if err != nil {
return nil, err
}

return cfg, nil

}

func NewBlankConfig() Config {
return NewConfig(&yaml.Node{
Kind: yaml.DocumentNode,
Expand Down

0 comments on commit cabf0b1

Please sign in to comment.