File tree Expand file tree Collapse file tree 2 files changed +28
-26
lines changed Expand file tree Collapse file tree 2 files changed +28
-26
lines changed Original file line number Diff line number Diff line change 2
2
package config
3
3
4
4
import (
5
- "bufio"
6
5
"errors"
7
6
"fmt"
7
+ "io"
8
8
"os"
9
9
"path/filepath"
10
10
@@ -104,28 +104,8 @@ func LookupAndParse() (*lint.Config, error) {
104
104
return conf , nil
105
105
}
106
106
107
- // WriteToFile util func to write config object to given file
108
- func WriteToFile (outFilePath string , conf * lint.Config ) (retErr error ) {
109
- outFilePath = filepath .Clean (outFilePath )
110
- f , err := os .Create (outFilePath )
111
- if err != nil {
112
- return err
113
- }
114
- defer func () {
115
- err := f .Close ()
116
- if retErr == nil && err != nil {
117
- retErr = err
118
- }
119
- }()
120
-
121
- w := bufio .NewWriter (f )
122
- defer func () {
123
- err := w .Flush ()
124
- if retErr == nil && err != nil {
125
- retErr = err
126
- }
127
- }()
128
-
107
+ // WriteTo writes config in yaml format to given io.Writer
108
+ func WriteTo (w io.Writer , conf * lint.Config ) (retErr error ) {
129
109
enc := yaml .NewEncoder (w )
130
110
defer func () {
131
111
err := enc .Close ()
Original file line number Diff line number Diff line change 1
1
package cmd
2
2
3
3
import (
4
+ "bufio"
4
5
"os"
5
6
"path/filepath"
6
7
7
8
"github.com/conventionalcommit/commitlint/config"
8
9
)
9
10
10
11
// configCreate is the callback function for create config command
11
- func configCreate (fileName string , isReplace bool ) error {
12
- defConf := config .Default ()
12
+ func configCreate (fileName string , isReplace bool ) (retErr error ) {
13
13
outPath := filepath .Join ("." , fileName )
14
14
// if config file already exists skip creating or overwriting it
15
15
if _ , err := os .Stat (outPath ); ! os .IsNotExist (err ) {
16
16
if ! isReplace {
17
17
return errConfigExist
18
18
}
19
19
}
20
- return config .WriteToFile (outPath , defConf )
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 .Default ()
42
+ return config .WriteTo (w , defConf )
21
43
}
22
44
23
45
// configCheck is the callback function for check/verify command
You can’t perform that action at this time.
0 commit comments