本文整理匯總了Golang中github.com/hashicorp/otto/ui.Ui.Raw方法的典型用法代碼示例。如果您正苦於以下問題:Golang Ui.Raw方法的具體用法?Golang Ui.Raw怎麽用?Golang Ui.Raw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/otto/ui.Ui
的用法示例。
在下文中一共展示了Ui.Raw方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
// Run runs the given command and streams all the output to the
// given UI. It also connects stdin properly so that input works as
// expected.
func Run(uiVal ui.Ui, cmd *exec.Cmd) error {
out_r, out_w := io.Pipe()
cmd.Stdin = os.Stdin
cmd.Stdout = out_w
cmd.Stderr = out_w
// Copy output to the UI until we can't.
output := false
uiDone := make(chan struct{})
go func() {
defer close(uiDone)
var buf [1024]byte
for {
n, err := out_r.Read(buf[:])
if n > 0 {
output = true
uiVal.Raw(string(buf[:n]))
}
// We just break on any error. io.EOF is not an error and
// is our true exit case, but any other error we don't really
// handle here. It probably means something went wrong
// somewhere else anyways.
if err != nil {
break
}
}
}()
// Run the command
log.Printf("[DEBUG] execDir: %s", cmd.Dir)
log.Printf("[DEBUG] exec: %s %s", cmd.Path, strings.Join(cmd.Args[1:], " "))
// Build a runnable command that we can log out to make things easier
// for debugging. This lets debuging devs just copy and paste the command.
logRunnableCommand(cmd)
// Run
err := Runner(cmd)
// Wait for all the output to finish
out_w.Close()
<-uiDone
if output {
// Output one extra newline to separate output from Otto. We only
// do this if there was any output to begin with.
uiVal.Message("")
}
// Return the output from the command
return err
}
示例2: Run
// Run runs the given command and streams all the output to the
// given UI. It also connects stdin properly so that input works as
// expected.
func Run(uiVal ui.Ui, cmd *exec.Cmd) error {
out_r, out_w := io.Pipe()
cmd.Stdin = os.Stdin
cmd.Stdout = out_w
cmd.Stderr = out_w
// Copy output to the UI until we can't.
uiDone := make(chan struct{})
go func() {
defer close(uiDone)
var buf [1024]byte
for {
n, err := out_r.Read(buf[:])
if n > 0 {
uiVal.Raw(string(buf[:n]))
}
// We just break on any error. io.EOF is not an error and
// is our true exit case, but any other error we don't really
// handle here. It probably means something went wrong
// somewhere else anyways.
if err != nil {
break
}
}
}()
// Run the command
log.Printf("[DEBUG] execDir: %s", cmd.Dir)
log.Printf("[DEBUG] exec: %s %s", cmd.Path, strings.Join(cmd.Args[1:], " "))
err := cmd.Run()
// Wait for all the output to finish
out_w.Close()
<-uiDone
// Output one extra newline to separate output from Otto
uiVal.Message("")
// Return the output from the command
return err
}