-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgoast.go
71 lines (57 loc) · 1.17 KB
/
goast.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package goast
import (
"io"
"io/fs"
"os"
"github.com/m-mizutani/opac"
)
type Goast struct {
opac opac.Client
inspectOpt []InspectOption
create func(path string) (io.WriteCloser, error)
mkdir func(path string, perm fs.FileMode) error
walk func(src string, cb func(fpath string, r io.Reader) error) error
dumpCompact bool
dumpHook DumpHook
ignoreAutoGen bool
}
type Option func(g *Goast)
func New(options ...Option) *Goast {
g := &Goast{
create: func(path string) (io.WriteCloser, error) {
return os.Create(path)
},
mkdir: os.MkdirAll,
walk: walkGoCode,
}
for _, opt := range options {
opt(g)
}
return g
}
func WithOpacClient(client opac.Client) Option {
return func(g *Goast) {
g.opac = client
}
}
func WithInspectOptions(options ...InspectOption) Option {
return func(g *Goast) {
g.inspectOpt = options
}
}
func WithDumpHook(hook DumpHook) Option {
return func(g *Goast) {
g.dumpHook = hook
}
}
type DumpHook func(node *Node, w io.Writer) error
func WithCompact(enable bool) Option {
return func(g *Goast) {
g.dumpCompact = enable
}
}
func WithIgnoreAutoGen() Option {
return func(g *Goast) {
g.ignoreAutoGen = true
}
}