populate initial config

This commit is contained in:
vilmibm 2020-06-10 16:37:07 -05:00
parent 85b418352e
commit cabf0b1972
2 changed files with 61 additions and 1 deletions

View file

@ -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
}

View file

@ -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,