added helpers Dereference, Default, Concrete options to compiler.Value

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-05-21 16:01:13 -07:00
parent 4edc2ad38e
commit df564dd877

View File

@ -145,8 +145,10 @@ func (v *Value) List() ([]*Value, error) {
}
// Recursive concreteness check.
func (v *Value) IsConcreteR() error {
return v.val.Validate(cue.Concrete(true))
func (v *Value) IsConcreteR(opts ...cue.Option) error {
o := []cue.Option{cue.Concrete(true)}
o = append(o, opts...)
return v.val.Validate(o...)
}
func (v *Value) Walk(before func(*Value) bool, after func(*Value)) {
@ -232,7 +234,7 @@ func (v *Value) Cue() cue.Value {
// Returns true if value has a dagger attribute (eg. artifact, secret, input)
func (v *Value) HasAttr(filter ...string) bool {
attrs := v.val.Attributes(cue.FieldAttr)
attrs := v.val.Attributes(cue.ValueAttr)
for _, attr := range attrs {
name := attr.Name()
@ -258,3 +260,13 @@ func (v *Value) HasAttr(filter ...string) bool {
return false
}
func (v *Value) Dereference() *Value {
dVal := cue.Dereference(v.val)
return v.cc.Wrap(dVal)
}
func (v *Value) Default() (*Value, bool) {
val, hasDef := v.val.Default()
return v.cc.Wrap(val), hasDef
}