mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-21 22:10:39 +00:00
refactor: isolate load config inside a function
This commit is contained in:
parent
8597819cfa
commit
2527563975
@ -52,7 +52,7 @@ func combinedOutputErr(err error, out []byte) error {
|
||||
return fmt.Errorf("%v - %s", err, msg[0])
|
||||
}
|
||||
|
||||
func loadConfig(filepath string) (Config, error) {
|
||||
func readConfig(filepath string) (Config, error) {
|
||||
content, rerr := ioutil.ReadFile(filepath)
|
||||
if rerr != nil {
|
||||
return Config{}, rerr
|
||||
|
@ -20,32 +20,7 @@ const (
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
|
||||
envCfg := loadEnvConfig()
|
||||
|
||||
cfg := defaultConfig()
|
||||
|
||||
if envCfg.Home != "" {
|
||||
if homeCfg, err := loadConfig(filepath.Join(envCfg.Home, configFilename)); err == nil {
|
||||
if merr := merge(&cfg, homeCfg); merr != nil {
|
||||
log.Fatal("failed to merge user config, error: ", merr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repoPath, rerr := getRepoPath()
|
||||
if rerr != nil {
|
||||
log.Fatal("failed to get repository path, error: ", rerr)
|
||||
}
|
||||
|
||||
if repoCfg, err := loadConfig(filepath.Join(repoPath, repoConfigFilename)); err == nil {
|
||||
if merr := merge(&cfg, repoCfg); merr != nil {
|
||||
log.Fatal("failed to merge repo config, error: ", merr)
|
||||
}
|
||||
if len(repoCfg.ReleaseNotes.Headers) > 0 { // mergo is merging maps, headers will be overwritten
|
||||
cfg.ReleaseNotes.Headers = repoCfg.ReleaseNotes.Headers
|
||||
}
|
||||
}
|
||||
|
||||
cfg := loadCfg()
|
||||
messageProcessor := sv.NewMessageProcessor(cfg.CommitMessage, cfg.Branches)
|
||||
git := sv.NewGit(messageProcessor, cfg.Tag)
|
||||
semverProcessor := sv.NewSemVerCommitsProcessor(cfg.Versioning, cfg.CommitMessage)
|
||||
@ -168,3 +143,33 @@ func main() {
|
||||
log.Fatal("failed to run cli, error: ", apperr)
|
||||
}
|
||||
}
|
||||
|
||||
func loadCfg() Config {
|
||||
envCfg := loadEnvConfig()
|
||||
|
||||
cfg := defaultConfig()
|
||||
|
||||
if envCfg.Home != "" {
|
||||
if homeCfg, err := readConfig(filepath.Join(envCfg.Home, configFilename)); err == nil {
|
||||
if merr := merge(&cfg, homeCfg); merr != nil {
|
||||
log.Fatal("failed to merge user config, error: ", merr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repoPath, rerr := getRepoPath()
|
||||
if rerr != nil {
|
||||
log.Fatal("failed to get repository path, error: ", rerr)
|
||||
}
|
||||
|
||||
if repoCfg, err := readConfig(filepath.Join(repoPath, repoConfigFilename)); err == nil {
|
||||
if merr := merge(&cfg, repoCfg); merr != nil {
|
||||
log.Fatal("failed to merge repo config, error: ", merr)
|
||||
}
|
||||
if len(repoCfg.ReleaseNotes.Headers) > 0 { // mergo is merging maps, headers will be overwritten
|
||||
cfg.ReleaseNotes.Headers = repoCfg.ReleaseNotes.Headers
|
||||
}
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user