hcl/zcl/merged.go
Martin Atkins 1ecde9204c Interface for treating several files as one file
Some applications treat an entire directory as a configuration, merging
the configurations from all of the files in a directory and treating them
as one.

MergeFiles supports this idea by wrapping the bodies of the several files.
It's not yet implemented here, but once implemented it will act as an
aggregator of the content of the wrapped bodies, delegating to them for
actual body content and then merging the returned body content in a
well-defined way.
2017-05-18 08:10:21 -07:00

36 lines
1.0 KiB
Go

package zcl
// MergeFiles combines the given files to produce a single body that contains
// configuration from all of the given files.
//
// The ordering of the given files decides the order in which contained
// elements will be returned. If any top-level attributes are defined with
// the same name across multiple files, a diagnostic will be produced from
// the Content and PartialContent methods describing this error in a
// user-friendly way.
func MergeFiles(files []*File) Body {
var bodies []Body
for _, file := range files {
bodies = append(bodies, file.Body)
}
return MergeBodies(bodies)
}
// MergeBodies is like MergeFiles except it deals directly with bodies, rather
// than with entire files.
func MergeBodies(bodies []Body) Body {
return mergedBodies(bodies)
}
type mergedBodies []Body
func (mb mergedBodies) Content(schema *BodySchema) (*BodyContent, Diagnostics) {
// TODO: Implement
return nil, nil
}
func (mb mergedBodies) PartialContent(schema *BodySchema) (*BodyContent, Body, Diagnostics) {
// TODO: Implement
return nil, nil, nil
}