2024-03-27 10:49:05 +00:00
|
|
|
package loader
|
2022-11-18 09:57:31 +00:00
|
|
|
|
|
|
|
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"
|
2024-03-25 14:18:47 +00:00
|
|
|
"github.com/databricks/cli/libs/diag"
|
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)
|
|
|
|
}
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
func (m *processInclude) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnostics {
|
2024-03-28 10:59:03 +00:00
|
|
|
this, diags := config.Load(m.fullPath)
|
|
|
|
if diags.HasError() {
|
|
|
|
return diags
|
|
|
|
}
|
|
|
|
err := b.Config.Merge(this)
|
2022-11-18 09:57:31 +00:00
|
|
|
if err != nil {
|
2024-03-28 10:59:03 +00:00
|
|
|
diags = diags.Extend(diag.FromErr(err))
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
2024-03-28 10:59:03 +00:00
|
|
|
return diags
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|