yq/pkg/yqlib/context.go

31 lines
568 B
Go
Raw Normal View History

package yqlib
2021-02-03 00:54:10 +00:00
import (
"container/list"
"github.com/jinzhu/copier"
)
type Context struct {
2021-02-03 00:54:10 +00:00
MatchingNodes *list.List
Variables map[string]*list.List
DontAutoCreate bool
}
func (n *Context) SingleChildContext(candidate *CandidateNode) Context {
2021-02-03 00:54:10 +00:00
list := list.New()
list.PushBack(candidate)
return n.ChildContext(list)
}
func (n *Context) ChildContext(results *list.List) Context {
2021-02-03 00:54:10 +00:00
clone := Context{}
err := copier.Copy(&clone, n)
if err != nil {
log.Error("Error cloning context :(")
panic(err)
}
clone.MatchingNodes = results
return clone
}