-
Notifications
You must be signed in to change notification settings - Fork 10
/
config.go
56 lines (49 loc) · 1.29 KB
/
config.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
package main
import (
"io/ioutil"
"github.com/codeskyblue/go-sh"
"github.com/gobuild/log"
goyaml "gopkg.in/yaml.v2"
)
type PackageConfig struct {
Author string `yaml:"author"`
Description string `yaml:"description"`
OS string `yaml:"os"`
Includes []string `yaml:"includes"`
Excludes []string `yaml:"excludes"`
Depth int `yaml:"-"`
Script []string `yaml:"script"`
Settings struct {
TargetDir string `yaml:"targetdir"` // target dir
Outfiles []string `yaml:"outfiles"`
} `yaml:"-"`
}
const RCFILE = ".gopack.yml"
var DEFAULT_SCRIPT = []string{"go get -v", "go build"}
var DefaultPcfg *PackageConfig = &PackageConfig{
OS: "darwin linux windows",
Includes: []string{"README.md", "LICENSE", "conf", "templates", "public", "static", "views"},
Excludes: []string{"\\.git"},
Depth: 20,
Script: DEFAULT_SCRIPT,
}
func init() {
if _, err := ReadPkgConfig(RCFILE); err != nil {
log.Warnf("Read %s err: %v", RCFILE, err)
}
}
// parse yaml
func ReadPkgConfig(filepath string) (pcfg *PackageConfig, err error) {
pcfg = DefaultPcfg
if sh.Test("file", filepath) {
data, er := ioutil.ReadFile(filepath)
if er != nil {
err = er
return
}
if err = goyaml.Unmarshal(data, &pcfg); err != nil {
return
}
}
return pcfg, nil
}