本文整理汇总了Golang中github.com/danwakefield/gosh/variables.Scope.Copy方法的典型用法代码示例。如果您正苦于以下问题:Golang Scope.Copy方法的具体用法?Golang Scope.Copy怎么用?Golang Scope.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/danwakefield/gosh/variables.Scope
的用法示例。
在下文中一共展示了Scope.Copy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Sub
func (s SubSubshell) Sub(scp *variables.Scope) (returnString string) {
logex.Debug("Substituting shell")
defer func() {
logex.Debugf("Returned '%s'", returnString)
}()
if _, isNoop := s.N.(NodeNoop); isNoop {
return ""
}
out := &bytes.Buffer{}
// Not sure if we need to capture this exit code for the $? var.
// Ignore it for now
_ = s.N.Eval(scp.Copy(), &T.IOContainer{&bytes.Buffer{}, out, os.Stderr})
return strings.TrimRight(out.String(), "\n")
}
示例2: Eval
func (n NodePipe) Eval(scp *variables.Scope, ioc *T.IOContainer) T.ExitStatus {
lastPipeReader, pipeWriter := io.Pipe()
scp = scp.Copy()
cmd := n.Commands[0]
go cmd.Eval(scp, &T.IOContainer{In: &bytes.Buffer{}, Out: pipeWriter, Err: ioc.Err})
for _, cmd = range n.Commands[1 : len(n.Commands)-1] {
pipeReader, pipeWriter := io.Pipe()
go cmd.Eval(scp, &T.IOContainer{In: lastPipeReader, Out: pipeWriter, Err: ioc.Err})
lastPipeReader = pipeReader
}
cmd = n.Commands[len(n.Commands)-1]
if !n.Background {
return cmd.Eval(scp, &T.IOContainer{In: lastPipeReader, Out: ioc.Out, Err: ioc.Err})
}
go cmd.Eval(scp, &T.IOContainer{In: lastPipeReader, Out: ioc.Out, Err: ioc.Err})
return T.ExitSuccess
}