2022-11-18 09:57:31 +00:00
|
|
|
package mutator
|
|
|
|
|
|
|
|
import (
|
2022-11-28 09:59:43 +00:00
|
|
|
"context"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
2022-11-18 09:57:31 +00:00
|
|
|
"golang.org/x/exp/slices"
|
|
|
|
)
|
|
|
|
|
|
|
|
type defineDefaultInclude struct {
|
|
|
|
include []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefineDefaultInclude sets the list of includes to a default if it hasn't been set.
|
2022-11-28 09:59:43 +00:00
|
|
|
func DefineDefaultInclude() bundle.Mutator {
|
2022-11-18 09:57:31 +00:00
|
|
|
return &defineDefaultInclude{
|
|
|
|
// When we support globstar we can collapse below into a single line.
|
|
|
|
include: []string{
|
|
|
|
// Load YAML files in the same directory.
|
|
|
|
"*.yml",
|
|
|
|
// Load YAML files in subdirectories.
|
|
|
|
"*/*.yml",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *defineDefaultInclude) Name() string {
|
|
|
|
return "DefineDefaultInclude"
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:45:19 +00:00
|
|
|
func (m *defineDefaultInclude) Apply(_ context.Context, b *bundle.Bundle) error {
|
2022-11-28 09:59:43 +00:00
|
|
|
if len(b.Config.Include) == 0 {
|
|
|
|
b.Config.Include = slices.Clone(m.include)
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
2023-05-24 12:45:19 +00:00
|
|
|
return nil
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|