databricks-cli/bundle/deferred.go

36 lines
653 B
Go
Raw Normal View History

2023-05-16 16:01:50 +00:00
package bundle
import (
"context"
"github.com/databricks/cli/libs/errs"
2023-05-16 16:01:50 +00:00
)
type DeferredMutator struct {
mutators []Mutator
finally []Mutator
}
func (d *DeferredMutator) Name() string {
return "deferred"
}
func Defer(mutators []Mutator, finally []Mutator) []Mutator {
return []Mutator{
&DeferredMutator{
mutators: mutators,
finally: finally,
},
}
}
func (d *DeferredMutator) Apply(ctx context.Context, b *Bundle) ([]Mutator, error) {
mainErr := Apply(ctx, b, d.mutators)
errOnFinish := Apply(ctx, b, d.finally)
if mainErr != nil || errOnFinish != nil {
return nil, errs.FromMany(mainErr, errOnFinish)
}
return nil, nil
}