github.com/please-build/go-rules/tools/please_go@v0.0.0-20240319165128-ea27d6f5caba/install/exec/exec.go (about) 1 package exec 2 3 import ( 4 "fmt" 5 "io" 6 "os" 7 "os/exec" 8 "strings" 9 ) 10 11 // Executor executes the command using the os/exec package 12 type Executor struct { 13 Stdout io.Writer 14 Stderr io.Writer 15 } 16 17 // Run runs the command 18 func (e *Executor) Run(cmdStr string, args ...interface{}) error { 19 cmdStr = fmt.Sprintf(cmdStr, args...) 20 fmt.Fprintf(os.Stderr, "please_go install -> %v\n", cmdStr) 21 22 cmd := exec.Command("bash", "-e", "-c", cmdStr) 23 cmd.Stdout = e.Stdout 24 cmd.Stderr = e.Stderr 25 26 return cmd.Run() 27 } 28 29 func (e *Executor) CombinedOutput(bin string, args ...string) ([]byte, error) { 30 fmt.Fprintln(os.Stderr, "please_go install ->", bin, strings.Join(args, " ")) 31 32 cmd := exec.Command(bin, args...) 33 return cmd.CombinedOutput() 34 }