Debian Codegraph @

execution/execute_all.go

raw symbols SCIP
1 package execution
2
3 import (
4 "context"
5 "fmt"
6
7 "github.com/tomwright/dasel/v3/model"
8 "github.com/tomwright/dasel/v3/selector/ast"
9 )
10
11 func allExprExecutor(e ast.AllExpr) (expressionExecutor, error) {
12 return func(ctx context.Context, options *Options, data *model.Value) (*model.Value, error) {
13 ctx = WithExecutorID(ctx, "allExpr")
14 if !data.IsSlice() {
15 return nil, fmt.Errorf("cannot use all over non-array")
16 }
17
18 result := true
19 if err := data.RangeSlice(func(i int, item *model.Value) error {
20 restore := withKeyVar(options, model.NewIntValue(int64(i)))
21 defer restore()
22
23 v, err := ExecuteAST(ctx, e.Expr, item, options)
24 if err != nil {
25 return err
26 }
27
28 boolV, err := v.BoolValue()
29 if err != nil {
30 return err
31 }
32
33 if !boolV {
34 result = false
35 }
36 return nil
37 }); err != nil {
38 return nil, fmt.Errorf("error ranging over slice: %w", err)
39 }
40
41 return model.NewBoolValue(result), nil
42 }, nil
43 }