| 1 | package execution |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "github.com/tomwright/dasel/v3/model" |
| 6 | ) |
| 7 | |
| 8 | // FuncMax is a function that returns the highest number. |
| 9 | var FuncMax = NewFunc( |
| 10 | "max", |
| 11 | func(ctx context.Context, data *model.Value, args model.Values) (*model.Value, error) { |
| 12 | res := model.NewNullValue() |
| 13 | for _, arg := range args { |
| 14 | if res.IsNull() { |
| 15 | res = arg |
| 16 | continue |
| 17 | } |
| 18 | gt, err := arg.GreaterThan(res) |
| 19 | if err != nil { |
| 20 | return nil, err |
| 21 | } |
| 22 | gtBool, err := gt.BoolValue() |
| 23 | if err != nil { |
| 24 | return nil, err |
| 25 | } |
| 26 | if gtBool { |
| 27 | res = arg |
| 28 | } |
| 29 | } |
| 30 | return res, nil |
| 31 | }, |
| 32 | ValidateArgsMin(1), |
| 33 | ) |