import ( "github.com/globocom/tsuru/cmd" "github.com/globocom/tsuru/cmd/cmdtest" ) func ExampleDoer_Do() { cmdtest.SetupTest(cmdtest.M{ "apiVersion": "1.23", "token": "sometoken", }) defer cmdtest.Rollback() d := &cmd.Doer{} output, err := d.Do("node-list") fmt.Println(output, err) }
import ( "github.com/globocom/tsuru/cmd" "github.com/globocom/tsuru/cmd/cmdtest" "io" "os" ) func ExampleDoer_DoWithPipe() { cmdtest.SetupTest(cmdtest.M{ "apiVersion": "1.23", "token": "sometoken", }) defer cmdtest.Rollback() d := &cmd.Doer{} r, w, _ := os.Pipe() d.Stdout = w go func() { for { buf := make([]byte, 512) n, err := r.Read(buf) if err != nil && err != io.EOF { fmt.Println("Error reading pipe:", err) } if n == 0 { break } fmt.Println(string(buf[:n])) } }() err := d.DoWithPipe([]string{"node-list"}) fmt.Println(err) }In summary, the Doer Do library in the github.com.globocom.tsuru.cmd package provides functions for executing Tsuru commands and capturing their output.