Debian Codegraph @

execution/func_has.go

raw symbols SCIP
1 package executionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/
2
3 import (
4 "contextscip-go gomod github.com/golang/go/src go1.25 context/"
5 "fmtscip-go gomod github.com/golang/go/src go1.25 fmt/"
6 "github.com/tomwright/dasel/v3/modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/"
7 )
8
9 // FuncHas is a function that true or false if the input has the given key/index.
10 var FuncHasscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/FuncHas. = NewFuncscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/NewFunc().(
11 "has",
12 func(ctxscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/FuncHas:ctx. contextscip-go gomod github.com/golang/go/src go1.25 context/.Contextscip-go gomod github.com/golang/go/src go1.25 context/Context#, datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/FuncHas:data. *modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, argsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/FuncHas:args. modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.Valuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Values#) (*modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#, error) {
13
14 arg := argsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/FuncHas:args.[0]
15
16 switch arg.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() {
17 case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeInt.:
18 // Given key is int, expect a slice.
19 if datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/FuncHas:data..Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() != modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeSlice. {
20 return modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewBoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewBoolValue().(false), nil
21 }
22 index, err := arg.IntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IntValue().()
23 if err != nil {
24 return nil, err
25 }
26 sliceLen, err := datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/FuncHas:data..SliceLenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SliceLen().()
27 if err != nil {
28 return nil, err
29 }
30 return modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewBoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewBoolValue().(index >= 0 && index < int64(sliceLen)), nil
31 case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeString.:
32 // Given key is string, expect a map.
33 if datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/FuncHas:data..Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() != modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeMap. {
34 return modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewBoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewBoolValue().(false), nil
35 }
36 key, err := arg.StringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#StringValue().()
37 if err != nil {
38 return nil, err
39 }
40 exists, err := datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/FuncHas:data..MapKeyExistsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapKeyExists().(key)
41 if err != nil {
42 return nil, err
43 }
44 return modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.NewBoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/NewBoolValue().(exists), nil
45 default:
46 return nil, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("has expects string or int argument")
47 }
48 },
49 ValidateArgsMinscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/execution`/ValidateArgsMin().(1),
50 )