...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package fix
16
17 import (
18 "os"
19
20 "cuelang.org/go/cue/ast"
21 "cuelang.org/go/cue/build"
22 "cuelang.org/go/cue/errors"
23 )
24
25
26
27
28 func Instances(a []*build.Instance, o ...Option) errors.Error {
29 cwd, _ := os.Getwd()
30
31
32 p := processor{
33 instances: a,
34 cwd: cwd,
35 }
36
37 p.visitAll(func(f *ast.File) { File(f, o...) })
38
39 return p.err
40 }
41
42 type processor struct {
43 instances []*build.Instance
44 cwd string
45
46 err errors.Error
47 }
48
49 func (p *processor) visitAll(fn func(f *ast.File)) {
50 if p.err != nil {
51 return
52 }
53
54 done := map[*ast.File]bool{}
55
56 for _, b := range p.instances {
57 for _, f := range b.Files {
58 if done[f] {
59 continue
60 }
61 done[f] = true
62 fn(f)
63 }
64 }
65 }
66
View as plain text