-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
50 lines (45 loc) · 869 Bytes
/
main.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
package main
import (
"fmt"
"go/ast"
"io"
"log"
"os"
"path/filepath"
"strings"
"github.com/hori-ryota/go-genconstructor/genconstructor"
)
func main() {
if err := Main(os.Args); err != nil {
log.Print(err)
fmt.Printf(`
Usage: %s [targetDir]
`, os.Args[0])
}
}
func Main(args []string) error {
targetDir := "."
if len(args) > 1 {
targetDir = args[1]
}
if err := genconstructor.Run(
targetDir,
func(pkg *ast.Package) io.Writer {
dstFileName := fmt.Sprintf("%s_constructor_gen.go", pkg.Name)
dstFilePath := filepath.Join(filepath.FromSlash(targetDir), dstFileName)
f, err := os.Create(dstFilePath)
if err != nil {
panic(err)
}
return f
},
genconstructor.WithFileFilter(
func(finfo os.FileInfo) bool {
return !strings.HasSuffix(finfo.Name(), "_test.go")
},
),
); err != nil {
return err
}
return nil
}