-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
52 lines (45 loc) · 1.04 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
package cmd
import (
"bufio"
"os"
"path/filepath"
"github.com/conventionalcommit/commitlint/config"
)
// configCreate is the callback function for create config command
func configCreate(fileName string, isReplace bool) (retErr error) {
outPath := filepath.Join(".", fileName)
// if config file already exists skip creating or overwriting it
if _, err := os.Stat(outPath); !os.IsNotExist(err) {
if !isReplace {
return errConfigExist
}
}
outFilePath := filepath.Clean(outPath)
f, err := os.Create(outFilePath)
if err != nil {
return err
}
defer func() {
err := f.Close()
if retErr == nil && err != nil {
retErr = err
}
}()
w := bufio.NewWriter(f)
defer func() {
err := w.Flush()
if retErr == nil && err != nil {
retErr = err
}
}()
defConf := config.NewDefault()
return config.WriteTo(w, defConf)
}
// configCheck is the callback function for check/verify command
func configCheck(confPath string) []error {
conf, err := config.Parse(confPath)
if err != nil {
return []error{err}
}
return config.Validate(conf)
}