Add new Client API
Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
This commit is contained in:
@@ -45,6 +45,14 @@ func (v *Value) FillFields(values map[string]interface{}) (*Value, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Fill updates a value, in place
|
||||
func (v *Value) Fill(value interface{}) (*Value, error) {
|
||||
if err := v.FillPath(cue.MakePath(), value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// LookupPath is a concurrency safe wrapper around cue.Value.LookupPath
|
||||
func (v *Value) LookupPath(p cue.Path) *Value {
|
||||
v.cc.rlock()
|
||||
@@ -93,6 +101,19 @@ func (f Field) Label() string {
|
||||
return l
|
||||
}
|
||||
|
||||
// ParentLabel returns the unquoted parent selector of a value
|
||||
func (v *Value) ParentLabel(depth int) string {
|
||||
sel := v.Path().Selectors()
|
||||
if depth > len(sel) {
|
||||
return ""
|
||||
}
|
||||
l := sel[len(sel)-depth].String()
|
||||
if unquoted, err := strconv.Unquote(l); err == nil {
|
||||
return unquoted
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
// Proxy function to the underlying cue.Value
|
||||
// Field ordering is guaranteed to be stable.
|
||||
func (v *Value) Fields(opts ...cue.Option) ([]Field, error) {
|
||||
|
Reference in New Issue
Block a user