本文整理匯總了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
}