databricks-cli/bundle/deferred.go

34 lines
593 B
Go
Raw Permalink 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 {
mutator Mutator
finally Mutator
2023-05-16 16:01:50 +00:00
}
func (d *DeferredMutator) Name() string {
return "deferred"
}
func Defer(mutator Mutator, finally Mutator) Mutator {
return &DeferredMutator{
mutator: mutator,
finally: finally,
2023-05-16 16:01:50 +00:00
}
}
func (d *DeferredMutator) Apply(ctx context.Context, b *Bundle) error {
mainErr := Apply(ctx, b, d.mutator)
2023-05-16 16:01:50 +00:00
errOnFinish := Apply(ctx, b, d.finally)
if mainErr != nil || errOnFinish != nil {
return errs.FromMany(mainErr, errOnFinish)
2023-05-16 16:01:50 +00:00
}
return nil
2023-05-16 16:01:50 +00:00
}