-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
539 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,10 @@ var ( | |
FuncTypeOf, | ||
FuncMax, | ||
FuncMin, | ||
FuncIgnore, | ||
FuncBase64Encode, | ||
FuncBase64Decode, | ||
FuncParse, | ||
) | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package execution | ||
|
||
import ( | ||
"encoding/base64" | ||
|
||
"github.com/tomwright/dasel/v3/model" | ||
) | ||
|
||
// FuncBase64Encode base64 encodes the given value. | ||
var FuncBase64Encode = NewFunc( | ||
"base64e", | ||
func(data *model.Value, args model.Values) (*model.Value, error) { | ||
arg := args[0] | ||
strVal, err := arg.StringValue() | ||
if err != nil { | ||
return nil, err | ||
} | ||
out := base64.StdEncoding.EncodeToString([]byte(strVal)) | ||
return model.NewStringValue(out), nil | ||
}, | ||
ValidateArgsExactly(1), | ||
) | ||
|
||
// FuncBase64Decode base64 decodes the given value. | ||
var FuncBase64Decode = NewFunc( | ||
"base64d", | ||
func(data *model.Value, args model.Values) (*model.Value, error) { | ||
arg := args[0] | ||
strVal, err := arg.StringValue() | ||
if err != nil { | ||
return nil, err | ||
} | ||
out, err := base64.StdEncoding.DecodeString(strVal) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return model.NewStringValue(string(out)), nil | ||
}, | ||
ValidateArgsExactly(1), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package execution | ||
|
||
import ( | ||
"github.com/tomwright/dasel/v3/model" | ||
) | ||
|
||
// FuncIgnore is a function that ignores the value, causing it to be rejected from a branch. | ||
var FuncIgnore = NewFunc( | ||
"ignore", | ||
func(data *model.Value, args model.Values) (*model.Value, error) { | ||
data.MarkAsIgnore() | ||
return data, nil | ||
}, | ||
ValidateArgsExactly(0), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package execution | ||
|
||
import ( | ||
"github.com/tomwright/dasel/v3/model" | ||
"github.com/tomwright/dasel/v3/parsing" | ||
) | ||
|
||
// FuncParse parses the given data at runtime. | ||
var FuncParse = NewFunc( | ||
"parse", | ||
func(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), | ||
) |
Oops, something went wrong.