MCPcopy Create free account
hub / github.com/conventionalcommit/commitlint / configCreate

Function configCreate

internal/cmd/config.go:12–46  ·  view source on GitHub ↗

configCreate is the callback function for create config command

(fileName string, isReplace bool, all bool)

Source from the content-addressed store, hash-verified

10
11// configCreate is the callback function for create config command
12func configCreate(fileName string, isReplace bool, all bool) (retErr error) {
13 outPath := filepath.Join(".", fileName)
14 // if config file already exists skip creating or overwriting it
15 if _, err := os.Stat(outPath); !os.IsNotExist(err) {
16 if !isReplace {
17 return errConfigExist
18 }
19 }
20
21 outFilePath := filepath.Clean(outPath)
22 f, err := os.Create(outFilePath)
23 if err != nil {
24 return err
25 }
26 defer func() {
27 err := f.Close()
28 if retErr == nil && err != nil {
29 retErr = err
30 }
31 }()
32
33 w := bufio.NewWriter(f)
34 defer func() {
35 err := w.Flush()
36 if retErr == nil && err != nil {
37 retErr = err
38 }
39 }()
40
41 defConf := config.NewDefault()
42 if all {
43 return config.WriteTo(w, defConf)
44 }
45 return config.WriteCompactTo(w, defConf)
46}
47
48// configCheck is the callback function for check/verify command
49func configCheck(confPath string) []error {

Callers 1

newConfigCmdFunction · 0.85

Calls 3

NewDefaultFunction · 0.92
WriteToFunction · 0.92
WriteCompactToFunction · 0.92

Tested by

no test coverage detected