|
|
|
@ -44,30 +44,43 @@ func NewDictSetContextV(flags DictSetFlag, varStores []map[string]string) *DictS
|
|
|
|
|
return ctx
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *DictSetContext) GetVar(name string) (value string, exists bool) {
|
|
|
|
|
if value, exists = self.localStore[name]; !exists {
|
|
|
|
|
value, exists = findInStores(name, self.varStores)
|
|
|
|
|
func (ctx *DictSetContext) GetVar(name string) (value string, exists bool) {
|
|
|
|
|
if value, exists = ctx.localStore[name]; !exists {
|
|
|
|
|
value, exists = ctx.findInStores(name)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *DictSetContext) SetVar(name string, value string) (repeatedValue string) {
|
|
|
|
|
self.localStore[name] = value
|
|
|
|
|
func (ctx *DictSetContext) SetVar(name string, value string) (repeatedValue string) {
|
|
|
|
|
ctx.localStore[name] = value
|
|
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func findInStores(key string, stores []map[string]string) (value string, found bool) {
|
|
|
|
|
for _, vars := range stores {
|
|
|
|
|
func (ctx *DictSetContext) findInStores(key string) (value string, found bool) {
|
|
|
|
|
if value, found = ctx.localStore[key]; !found {
|
|
|
|
|
for _, vars := range ctx.varStores {
|
|
|
|
|
if vars != nil {
|
|
|
|
|
if value, found = vars[key]; found {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *DictSetContext) Handle(spec string, scanFlags ScannerFlag) (value string, err error) {
|
|
|
|
|
// func findInStores(key string, stores []map[string]string) (value string, found bool) {
|
|
|
|
|
// for _, vars := range stores {
|
|
|
|
|
// if vars != nil {
|
|
|
|
|
// if value, found = vars[key]; found {
|
|
|
|
|
// break
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
func (ctx *DictSetContext) Handle(spec string, scanFlags ScannerFlag) (value string, err error) {
|
|
|
|
|
var found bool
|
|
|
|
|
var rawValue string
|
|
|
|
|
|
|
|
|
@ -81,30 +94,30 @@ func (self *DictSetContext) Handle(spec string, scanFlags ScannerFlag) (value st
|
|
|
|
|
rawValue = name
|
|
|
|
|
found = true
|
|
|
|
|
} else {
|
|
|
|
|
rawValue, found = findInStores(name, self.varStores)
|
|
|
|
|
rawValue, found = ctx.findInStores(name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.SetVar(pipeNameKey, name) // NOTE Maybe this line can be deleted
|
|
|
|
|
ctx.SetVar(pipeNameKey, name) // NOTE Maybe this line can be deleted
|
|
|
|
|
|
|
|
|
|
origVarFound := found
|
|
|
|
|
for _, part := range parts {
|
|
|
|
|
var expandedPart string
|
|
|
|
|
self.varStores[0][pipeValueKey] = rawValue
|
|
|
|
|
self.SetVar(pipeValueKey, rawValue)
|
|
|
|
|
if expandedPart, err = Scan(self, part); err != nil {
|
|
|
|
|
ctx.varStores[0][pipeValueKey] = rawValue
|
|
|
|
|
ctx.SetVar(pipeValueKey, rawValue)
|
|
|
|
|
if expandedPart, err = Scan(ctx, part); err != nil {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
self.SetVar(pipeNameKey, name)
|
|
|
|
|
if rawValue, err = self.evalContent(origVarFound, rawValue, expandedPart); err != nil {
|
|
|
|
|
ctx.SetVar(pipeNameKey, name)
|
|
|
|
|
if rawValue, err = ctx.evalContent(origVarFound, rawValue, expandedPart); err != nil {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
origVarFound = true
|
|
|
|
|
}
|
|
|
|
|
if err == nil {
|
|
|
|
|
if len(rawValue) == 0 && (self.flags&KeepVar) != 0 {
|
|
|
|
|
if len(rawValue) == 0 && (ctx.flags&KeepVar) != 0 {
|
|
|
|
|
value = Var(name)
|
|
|
|
|
} else {
|
|
|
|
|
value, err = Scan(self, rawValue)
|
|
|
|
|
value, err = Scan(ctx, rawValue)
|
|
|
|
|
//value = rawValue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -116,7 +129,7 @@ func (self *DictSetContext) Handle(spec string, scanFlags ScannerFlag) (value st
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (self *DictSetContext) evalContent(varFound bool, rawValue string, alternateValue string) (value string, err error) {
|
|
|
|
|
func (ctx *DictSetContext) evalContent(varFound bool, rawValue string, alternateValue string) (value string, err error) {
|
|
|
|
|
var args []string
|
|
|
|
|
if args, err = sq.Split(alternateValue); err != nil {
|
|
|
|
|
return
|
|
|
|
@ -127,8 +140,8 @@ func (self *DictSetContext) evalContent(varFound bool, rawValue string, alternat
|
|
|
|
|
op := args[0]
|
|
|
|
|
if strings.HasPrefix(op, "__") {
|
|
|
|
|
var f ExpanderFunc
|
|
|
|
|
if f, err = self.GetFunc(op); err == nil {
|
|
|
|
|
value, err = f(self, rawValue, args[1:])
|
|
|
|
|
if f, err = ctx.GetFunc(op); err == nil {
|
|
|
|
|
value, err = f(ctx, rawValue, args[1:])
|
|
|
|
|
}
|
|
|
|
|
} else if varFound {
|
|
|
|
|
value = rawValue
|
|
|
|
|