-
-
Notifications
You must be signed in to change notification settings - Fork 167
Expand file tree
/
Copy pathfunc_parse.go
More file actions
43 lines (38 loc) · 824 Bytes
/
func_parse.go
File metadata and controls
43 lines (38 loc) · 824 Bytes
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
package execution
import (
"context"
"github.com/tomwright/dasel/v3/model"
"github.com/tomwright/dasel/v3/parsing"
)
// FuncParse parses the given data at runtime.
var FuncParse = NewFunc(
"parse",
func(ctx context.Context, data *model.Value, args model.Values) (*model.Value, error) {
var format parsing.Format
var content []byte
{
strVal, err := args[0].StringValue()
if err != nil {
return nil, err
}
format = parsing.Format(strVal)
}
{
strVal, err := args[1].StringValue()
if err != nil {
return nil, err
}
content = []byte(strVal)
}
reader, err := format.NewReader(parsing.DefaultReaderOptions())
if err != nil {
return nil, err
}
doc, err := reader.Read(content)
if err != nil {
return nil, err
}
return doc, nil
},
ValidateArgsExactly(2),
)