-
Notifications
You must be signed in to change notification settings - Fork 77
/
op_prune.go
66 lines (51 loc) · 1.29 KB
/
op_prune.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
package spruce
import (
"fmt"
"github.com/starkandwayne/goutils/tree"
. "github.com/geofffranks/spruce/log"
)
var keysToPrune []string
func addToPruneListIfNecessary(paths ...string) {
for _, path := range paths {
if !isIncluded(keysToPrune, path) {
DEBUG("adding '%s' to the list of paths to prune", path)
keysToPrune = append(keysToPrune, path)
}
}
}
func isIncluded(list []string, name string) bool {
for _, entry := range list {
if entry == name {
return true
}
}
return false
}
// PruneOperator ...
type PruneOperator struct{}
// Setup ...
func (PruneOperator) Setup() error {
return nil
}
// Phase ...
func (PruneOperator) Phase() OperatorPhase {
return EvalPhase
}
// Dependencies ...
func (PruneOperator) Dependencies(_ *Evaluator, _ []*Expr, _ []*tree.Cursor, auto []*tree.Cursor) []*tree.Cursor {
return auto
}
// Run ...
func (PruneOperator) Run(ev *Evaluator, args []*Expr) (*Response, error) {
DEBUG("running (( prune ... )) operation at $.%s", ev.Here)
defer DEBUG("done with (( prune ... )) operation at $.%s\n", ev.Here)
addToPruneListIfNecessary(fmt.Sprintf("%s", ev.Here))
// simply replace it with nil (will be pruned at the end anyway)
return &Response{
Type: Replace,
Value: nil,
}, nil
}
func init() {
RegisterOp("prune", PruneOperator{})
}