Replies: 2 comments 8 replies
-
What would you need the filename for? For example, if it's for reporting an error, #943 would allow you to use error messages for "bottom", meaning that a user could see a friendly error with the filename and position where it's written. |
Beta Was this translation helpful? Give feedback.
-
I need this kind of metadata also, and have opted to use the In a library utility: package entry
import (
"path"
"strings"
)
// parameters is the top level field for the user serviced config
// Ensure we have this field.
#hasParametersField: {
parameters: _
}
// extract name from filename
// #in is the input injected at call site by --with-context, it can be placed in the main cue schema.
// we also lift the enclosing parameters to top level (it is a domain requirement to not have the parameter field)
#nameFromFilename: {
#in: _
for _name, _content in #in {
{
_isYaml: _name & =~#"\.yaml$"#
Name: strings.TrimSuffix(path.Base(_name), ".yaml")
} & _content.parameters // lift the contained parameters
}
} Given a file tree like so:
Where my-config-filename.yaml is
And config-schema.cue: // input has the form input: "filename": content when called --with-context -l '_input' -l 'filename'
_input: [string]: entry.#hasParametersField
// build a hidden _parameters which has the deduced Name
_parameters: {#in:_input} & entry.#nameFromFilename
#config: {
// enforced schema
Name: string // needed to satisfy the unification below
otherField: string // user defined constraint
}
// yield a unified config
_parameters & #config I validate using this call:
I export using this call:
|
Beta Was this translation helpful? Give feedback.
-
I would like to capture the filename in a let expression scoped to that file.
Beta Was this translation helpful? Give feedback.
All reactions