From cabf0b19727fd02ebef733715fe068f685a8d50b Mon Sep 17 00:00:00 2001 From: vilmibm Date: Wed, 10 Jun 2020 16:37:07 -0500 Subject: [PATCH] populate initial config --- context/context.go | 5 ++- internal/config/config_type.go | 57 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/context/context.go b/context/context.go index 236f9e722..24f81142c 100644 --- a/context/context.go +++ b/context/context.go @@ -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 } diff --git a/internal/config/config_type.go b/internal/config/config_type.go index 8db26f965..7f98341b3 100644 --- a/internal/config/config_type.go +++ b/internal/config/config_type.go @@ -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,