2023-11-08 11:01:14 +00:00
|
|
|
package mutator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config/variable"
|
2024-03-25 14:18:47 +00:00
|
|
|
"github.com/databricks/cli/libs/diag"
|
2023-11-08 11:01:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type initializeVariables struct{}
|
|
|
|
|
|
|
|
// InitializeVariables initializes nil variables to their corresponding zero values.
|
|
|
|
func InitializeVariables() bundle.Mutator {
|
|
|
|
return &initializeVariables{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *initializeVariables) Name() string {
|
|
|
|
return "InitializeVariables"
|
|
|
|
}
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
func (m *initializeVariables) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
2023-11-08 11:01:14 +00:00
|
|
|
vars := b.Config.Variables
|
|
|
|
for k, v := range vars {
|
|
|
|
if v == nil {
|
|
|
|
vars[k] = &variable.Variable{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|