本文整理汇总了Golang中github.com/danwakefield/gosh/variables.Scope.Push方法的典型用法代码示例。如果您正苦于以下问题:Golang Scope.Push方法的具体用法?Golang Scope.Push怎么用?Golang Scope.Push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/danwakefield/gosh/variables.Scope
的用法示例。
在下文中一共展示了Scope.Push方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Eval
func (n NodeCommand) Eval(scp *variables.Scope, ioc *T.IOContainer) T.ExitStatus {
// A line with only assignments applies them to the Root Scope
// We check this first to avoid unnecessary scope Push/Pop's
if len(n.Args) == 0 {
for k, v := range n.Assign {
scp.Set(k, v.Expand(scp))
}
return T.ExitSuccess
}
// Minimum of len(n.Args) after expansions, Likely
// that it will be more after globbing though
expandedArgs := []string{}
for _, arg := range n.Args {
expandedArgs = append(expandedArgs, arg.Expand(scp))
}
// Order of precedence:
// Relative command > Builtin > User Function > Other external command
command := expandedArgs[0]
builtinFunc, builtinFound := builtins.All[command]
userFunc, userFuncFound := scp.Functions[command]
if strings.ContainsRune(command, '/') || (!builtinFound && !userFuncFound) {
scp.Push()
defer scp.Pop()
for k, v := range n.Assign {
scp.Set(k, v.Expand(scp), variables.LocalScope)
}
return n.execExternal(scp, ioc, expandedArgs)
}
if builtinFound {
return builtinFunc(scp, ioc, expandedArgs[1:])
}
if userFuncFound {
x := userFunc.(NodeFunction)
return x.EvalFunc(scp, ioc, expandedArgs[1:])
}
return T.ExitUnknownCommand
}