-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
57 lines (46 loc) · 1.48 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
57
package main
import (
"errors"
"fmt"
"io/ioutil"
"gopkg.in/yaml.v2"
)
type config struct {
DepWarnning string
Script []string `yaml:"script"`
Build []string `yaml:"build"`
Run []string `yaml:"run"`
IgnoredItems []string `yaml:"ignore"`
Verbose bool `yaml:"verbose"`
}
func parseConfig() (config, error) {
var c config
// if we have any cliCmds, set them to our build phase
c.Build = cliCmds
// if build phase is still empty try and find the snag.yml file
if len(c.Build) == 0 {
in, err := ioutil.ReadFile(SnagFile)
if err != nil {
return c, fmt.Errorf("could not find %q in your current directory", SnagFile)
}
if err := yaml.Unmarshal(in, &c); err != nil {
return c, fmt.Errorf("could not parse snag file: %s\n", err)
}
}
// if both script and build are specified
// blow up and tell the user to use build
if len(c.Script) != 0 && len(c.Build) != 0 {
return c, errors.New("cannot use 'script' and 'build' together. The 'script' tag is deprecated, please use 'build' instead.")
}
// if script has something, tell the user it's deprecated
// and set whatever its contents are to build
if len(c.Script) != 0 {
c.DepWarnning += "*\tThe use of 'script' in the yaml file has been deprecated and will be removed in the future.\n\tPlease start using 'build' instead.\n\n"
c.Build = c.Script
}
if len(c.Build) == 0 {
return c, errors.New("you must specify at least 1 command.")
}
c.Verbose = verbose || c.Verbose
return c, nil
}