Debian Codegraph @

execution/func_to_upper.go

raw symbols SCIP
1 package execution
2
3 import (
4 "context"
5 "fmt"
6 "strings"
7
8 "github.com/tomwright/dasel/v3/model"
9 )
10
11 // FuncToUpper is a function that converts a string to uppercase.
12 var FuncToUpper = NewFunc(
13 "toUpper",
14 func(ctx context.Context, data *model.Value, args model.Values) (*model.Value, error) {
15 var input string
16 var err error
17 if len(args) == 1 {
18 input, err = args[0].StringValue()
19 if err != nil {
20 return nil, fmt.Errorf("toUpper expects a string argument: %w", err)
21 }
22 } else {
23 input, err = data.StringValue()
24 if err != nil {
25 return nil, fmt.Errorf("toUpper expects data to be a string: %w", err)
26 }
27 }
28 return model.NewStringValue(strings.ToUpper(input)), nil
29 },
30 ValidateArgsMax(1),
31 )