Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions api/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Result struct {
// can place anything they want in here and grab it from the context with
// the `gdtcontext.PriorRunData()` function. Plugins are responsible for
// clearing and setting any used prior run data.
data map[string]interface{}
data map[string]any
}

// HasData returns true if any of the run data has been set, false otherwise.
Expand All @@ -32,7 +32,7 @@ func (r *Result) HasData() bool {
}

// Data returns the raw run data saved in the result
func (r *Result) Data() map[string]interface{} {
func (r *Result) Data() map[string]any {
return r.data
}

Expand All @@ -50,10 +50,10 @@ func (r *Result) Failures() []error {
// SetData sets a value in the result's run data cache.
func (r *Result) SetData(
key string,
val interface{},
val any,
) {
if r.data == nil {
r.data = map[string]interface{}{}
r.data = map[string]any{}
}
r.data[key] = val
}
Expand All @@ -66,7 +66,7 @@ func (r *Result) SetFailures(failures ...error) {
type ResultModifier func(*Result)

// WithData modifies the Result with the supplied run data key and value
func WithData(key string, val interface{}) ResultModifier {
func WithData(key string, val any) ResultModifier {
return func(r *Result) {
r.SetData(key, val)
}
Expand Down
22 changes: 15 additions & 7 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
traceKey = ContextKey("gdt.trace")
pluginsKey = ContextKey("gdt.plugins")
fixturesKey = ContextKey("gdt.fixtures")
priorRunKey = ContextKey("gdt.run.prior")
runKey = ContextKey("gdt.run")
)

// ContextModifier sets some value on the context
Expand Down Expand Up @@ -145,16 +145,24 @@ func RegisterPlugin(
return context.WithValue(ctx, pluginsKey, plugins)
}

// StorePriorRun saves prior run data in the context. If there is already prior
// run data cached in the supplied context, the existing data is merged with
// the supplied data.
func StorePriorRun(
// SetRun saves run data in the context. If there is already prior run data
// cached in the supplied context, the existing data is merged with the
// supplied data.
func SetRun(
ctx context.Context,
data map[string]interface{},
data map[string]any,
) context.Context {
existing := PriorRun(ctx)
merged := lo.Assign(existing, data)
return context.WithValue(ctx, priorRunKey, merged)
return context.WithValue(ctx, runKey, merged)
}

// deprecated. use SetRun()
func StorePriorRun(
ctx context.Context,
data map[string]any,
) context.Context {
return SetRun(ctx, data)
}

// PushTrace pushes a debug/trace name onto the debug/trace stack. It is used
Expand Down
17 changes: 11 additions & 6 deletions context/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,20 @@ func Fixtures(ctx context.Context) map[string]api.Fixture {
return map[string]api.Fixture{}
}

// PriorRun gets a context's prior run data
func PriorRun(ctx context.Context) map[string]interface{} {
// Run gets a context's run data
func Run(ctx context.Context) map[string]any {
if ctx == nil {
return map[string]interface{}{}
return map[string]any{}
}
if v := ctx.Value(priorRunKey); v != nil {
return v.(map[string]interface{})
if v := ctx.Value(runKey); v != nil {
return v.(map[string]any)
}
return map[string]interface{}{}
return map[string]any{}
}

// deprecated: use Run()
func PriorRun(ctx context.Context) map[string]any {
return Run(ctx)
}

// ReplaceVariables replaces all occurrences of any of the variables in the
Expand Down
12 changes: 12 additions & 0 deletions plugin/exec/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ var (
ErrExecInvalid = fmt.Errorf(
"%w: invalid exec field", api.ErrParse,
)
// ErrUnknownShell returns an ErrParse when an unknown shell is specified
ErrUnknownShell = fmt.Errorf(
"%w: unknown shell", api.ErrParse,
)
)

// ExecEmpty returns an ErrExecEmpty with the line/column of the supplied YAML
Expand All @@ -46,3 +50,11 @@ func ExecInvalidShellParse(err error, node *yaml.Node) error {
func ExecRuntimeError(err error) error {
return fmt.Errorf("%w: %s", api.RuntimeError, err)
}

// ExecUnknownShell returns a wrapped version of ErrParse that indicates the
// user specified an unknown shell.
func ExecUnknownShell(shell string) error {
return fmt.Errorf(
"%w: %s", ErrUnknownShell, shell,
)
}
18 changes: 1 addition & 17 deletions plugin/exec/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package exec

import (
"fmt"
"os/exec"
"strconv"
"strings"
Expand All @@ -17,21 +16,6 @@ import (
"github.com/gdt-dev/core/api"
)

var (
// ErrUnknownShell returns an ErrParse when an unknown shell is specified
ErrUnknownShell = fmt.Errorf(
"%w: unknown shell", api.ErrParse,
)
)

// UnknownShell returns a wrapped version of ErrParse that indicates the
// user specified an unknown shell.
func UnknownShell(shell string) error {
return fmt.Errorf(
"%w: %s", ErrUnknownShell, shell,
)
}

func (s *Spec) UnmarshalYAML(node *yaml.Node) error {
if node.Kind != yaml.MappingNode {
return api.ExpectedMapAt(node)
Expand Down Expand Up @@ -87,7 +71,7 @@ func (s *Spec) UnmarshalYAML(node *yaml.Node) error {
}
s.Shell = strings.TrimSpace(valNode.Value)
if _, err := exec.LookPath(s.Shell); err != nil {
return UnknownShell(s.Shell)
return ExecUnknownShell(s.Shell)
}
case "exec":
if valNode.Kind != yaml.ScalarNode {
Expand Down
Loading