2022-11-18 09:57:31 +00:00
|
|
|
package mutator
|
|
|
|
|
|
|
|
import (
|
2022-11-28 09:59:43 +00:00
|
|
|
"context"
|
2022-11-18 09:57:31 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
2022-11-18 09:57:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type processInclude struct {
|
|
|
|
fullPath string
|
|
|
|
relPath string
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProcessInclude loads the configuration at [fullPath] and merges it into the configuration.
|
2022-11-28 09:59:43 +00:00
|
|
|
func ProcessInclude(fullPath, relPath string) bundle.Mutator {
|
2022-11-18 09:57:31 +00:00
|
|
|
return &processInclude{
|
|
|
|
fullPath: fullPath,
|
|
|
|
relPath: relPath,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *processInclude) Name() string {
|
|
|
|
return fmt.Sprintf("ProcessInclude(%s)", m.relPath)
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
func (m *processInclude) Apply(_ context.Context, b *bundle.Bundle) error {
|
2022-11-18 09:57:31 +00:00
|
|
|
this, err := config.Load(m.fullPath)
|
|
|
|
if err != nil {
|
2023-05-24 12:45:19 +00:00
|
|
|
return err
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
2023-05-24 12:45:19 +00:00
|
|
|
return b.Config.Merge(this)
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|