-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathbind.go
49 lines (43 loc) · 935 Bytes
/
bind.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
package runn
import (
"context"
"fmt"
"sort"
"github.com/k1LoW/runn/internal/store"
"github.com/samber/lo"
)
const bindRunnerKey = "bind"
type bindRunner struct{}
func newBindRunner() *bindRunner {
return &bindRunner{}
}
func (rnr *bindRunner) Run(ctx context.Context, s *step, first bool) error {
o := s.parent
cond := s.bindCond
sm := o.store.ToMap()
sm[store.RootKeyIncluded] = o.included
if first {
if !s.deferred {
sm[store.RootKeyPrevious] = o.store.Latest()
}
} else {
if !s.deferred {
sm[store.RootKeyPrevious] = o.store.Previous()
}
sm[store.RootKeyCurrent] = o.store.Latest()
}
keys := lo.Keys(cond)
sort.Slice(keys, func(i, j int) bool {
return keys[i] < keys[j]
})
for _, k := range keys {
v := cond[k]
if err := o.store.RecordBindVar(k, v, sm); err != nil {
return fmt.Errorf("failed to record bind vars: %w", err)
}
}
if first {
o.record(s.idx, nil)
}
return nil
}