-
Notifications
You must be signed in to change notification settings - Fork 65
/
config_parser.go
77 lines (63 loc) · 1.72 KB
/
config_parser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package config_parser
import (
"fmt"
"os"
"path"
"path/filepath"
"github.com/ejoffe/rake"
"github.com/ejoffe/spr/config"
"github.com/ejoffe/spr/git"
)
func ParseConfig(gitcmd git.GitInterface) *config.Config {
cfg := config.EmptyConfig()
rake.LoadSources(cfg.Repo,
rake.DefaultSource(),
NewGitHubRemoteSource(cfg, gitcmd),
rake.YamlFileSource(RepoConfigFilePath(gitcmd)),
)
if cfg.Repo.GitHubHost == "" {
fmt.Println("unable to auto configure repository host - must be set manually in .spr.yml")
os.Exit(2)
}
if cfg.Repo.GitHubRepoOwner == "" {
fmt.Println("unable to auto configure repository owner - must be set manually in .spr.yml")
os.Exit(3)
}
if cfg.Repo.GitHubRepoName == "" {
fmt.Println("unable to auto configure repository name - must be set manually in .spr.yml")
os.Exit(4)
}
rake.LoadSources(cfg.User,
rake.DefaultSource(),
rake.YamlFileSource(UserConfigFilePath()),
)
rake.LoadSources(cfg.Internal,
rake.DefaultSource(),
NewRemoteBranchSource(gitcmd),
)
rake.LoadSources(cfg.State,
rake.DefaultSource(),
rake.YamlFileSource(InternalConfigFilePath()),
)
cfg.State.RunCount = cfg.State.RunCount + 1
rake.LoadSources(cfg.State,
rake.YamlFileWriter(InternalConfigFilePath()))
return cfg
}
func RepoConfigFilePath(gitcmd git.GitInterface) string {
rootdir := gitcmd.RootDir()
filepath := filepath.Clean(path.Join(rootdir, ".spr.yml"))
return filepath
}
func UserConfigFilePath() string {
rootdir, err := os.UserHomeDir()
check(err)
filepath := filepath.Clean(path.Join(rootdir, ".spr.yml"))
return filepath
}
func InternalConfigFilePath() string {
rootdir, err := os.UserHomeDir()
check(err)
filepath := filepath.Clean(path.Join(rootdir, ".spr.state"))
return filepath
}