mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
55 lines
1.0 KiB
Go
55 lines
1.0 KiB
Go
package yqlib
|
|
|
|
import (
|
|
"container/list"
|
|
|
|
"github.com/jinzhu/copier"
|
|
)
|
|
|
|
type Context struct {
|
|
MatchingNodes *list.List
|
|
Variables map[string]*list.List
|
|
DontAutoCreate bool
|
|
}
|
|
|
|
func (n *Context) SingleChildContext(candidate *CandidateNode) Context {
|
|
list := list.New()
|
|
list.PushBack(candidate)
|
|
return n.ChildContext(list)
|
|
}
|
|
|
|
func (n *Context) GetVariable(name string) *list.List {
|
|
if n.Variables == nil {
|
|
return nil
|
|
}
|
|
return n.Variables[name]
|
|
}
|
|
|
|
func (n *Context) SetVariable(name string, value *list.List) {
|
|
if n.Variables == nil {
|
|
n.Variables = make(map[string]*list.List)
|
|
}
|
|
n.Variables[name] = value
|
|
}
|
|
|
|
func (n *Context) ChildContext(results *list.List) Context {
|
|
clone := Context{}
|
|
err := copier.Copy(&clone, n)
|
|
if err != nil {
|
|
log.Error("Error cloning context :(")
|
|
panic(err)
|
|
}
|
|
clone.MatchingNodes = results
|
|
return clone
|
|
}
|
|
|
|
func (n *Context) Clone() Context {
|
|
clone := Context{}
|
|
err := copier.Copy(&clone, n)
|
|
if err != nil {
|
|
log.Error("Error cloning context :(")
|
|
panic(err)
|
|
}
|
|
return clone
|
|
}
|