mirror of https://github.com/databricks/cli.git
Materialize glob expansion in configuration struct (#217)
This is needed to figure out which files should adhere to the schema.
This commit is contained in:
parent
7398a6d1e4
commit
9912ee1f92
|
@ -30,6 +30,10 @@ func (m *processRootIncludes) Apply(_ context.Context, b *bundle.Bundle) ([]bund
|
||||||
config.FileName: true,
|
config.FileName: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maintain list of files in order of files being loaded.
|
||||||
|
// This is stored in the bundle configuration for observability.
|
||||||
|
var files []string
|
||||||
|
|
||||||
// For each glob, find all files to load.
|
// For each glob, find all files to load.
|
||||||
// Ordering of the list of globs is maintained in the output.
|
// Ordering of the list of globs is maintained in the output.
|
||||||
// For matches that appear in multiple globs, only the first is kept.
|
// For matches that appear in multiple globs, only the first is kept.
|
||||||
|
@ -61,10 +65,14 @@ func (m *processRootIncludes) Apply(_ context.Context, b *bundle.Bundle) ([]bund
|
||||||
|
|
||||||
// Add matches to list of mutators to return.
|
// Add matches to list of mutators to return.
|
||||||
slices.Sort(includes)
|
slices.Sort(includes)
|
||||||
|
files = append(files, includes...)
|
||||||
for _, include := range includes {
|
for _, include := range includes {
|
||||||
out = append(out, ProcessInclude(filepath.Join(b.Config.Path, include), include))
|
out = append(out, ProcessInclude(filepath.Join(b.Config.Path, include), include))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Swap out the original includes list with the expanded globs.
|
||||||
|
b.Config.Include = files
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,7 @@ func TestProcessRootIncludesSingleGlob(t *testing.T) {
|
||||||
assert.NotContains(t, names, "ProcessInclude(bundle.yml)")
|
assert.NotContains(t, names, "ProcessInclude(bundle.yml)")
|
||||||
assert.Contains(t, names, "ProcessInclude(a.yml)")
|
assert.Contains(t, names, "ProcessInclude(a.yml)")
|
||||||
assert.Contains(t, names, "ProcessInclude(b.yml)")
|
assert.Contains(t, names, "ProcessInclude(b.yml)")
|
||||||
|
assert.Equal(t, []string{"a.yml", "b.yml"}, bundle.Config.Include)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProcessRootIncludesMultiGlob(t *testing.T) {
|
func TestProcessRootIncludesMultiGlob(t *testing.T) {
|
||||||
|
@ -102,6 +103,7 @@ func TestProcessRootIncludesMultiGlob(t *testing.T) {
|
||||||
|
|
||||||
assert.Contains(t, names, "ProcessInclude(a1.yml)")
|
assert.Contains(t, names, "ProcessInclude(a1.yml)")
|
||||||
assert.Contains(t, names, "ProcessInclude(b1.yml)")
|
assert.Contains(t, names, "ProcessInclude(b1.yml)")
|
||||||
|
assert.Equal(t, []string{"a1.yml", "b1.yml"}, bundle.Config.Include)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProcessRootIncludesRemoveDups(t *testing.T) {
|
func TestProcessRootIncludesRemoveDups(t *testing.T) {
|
||||||
|
@ -121,4 +123,5 @@ func TestProcessRootIncludesRemoveDups(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, ms, 1)
|
assert.Len(t, ms, 1)
|
||||||
assert.Equal(t, "ProcessInclude(a.yml)", ms[0].Name())
|
assert.Equal(t, "ProcessInclude(a.yml)", ms[0].Name())
|
||||||
|
assert.Equal(t, []string{"a.yml"}, bundle.Config.Include)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue