github.com/vipernet-xyz/tm@v0.34.24/test/e2e/runner/exec.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 osexec "os/exec" 7 "path/filepath" 8 ) 9 10 // execute executes a shell command. 11 func exec(args ...string) error { 12 //nolint:gosec // G204: Subprocess launched with a potential tainted input or cmd arguments 13 cmd := osexec.Command(args[0], args[1:]...) 14 out, err := cmd.CombinedOutput() 15 switch err := err.(type) { 16 case nil: 17 return nil 18 case *osexec.ExitError: 19 return fmt.Errorf("failed to run %q:\n%v", args, string(out)) 20 default: 21 return err 22 } 23 } 24 25 // execVerbose executes a shell command while displaying its output. 26 func execVerbose(args ...string) error { 27 //nolint:gosec // G204: Subprocess launched with a potential tainted input or cmd arguments 28 cmd := osexec.Command(args[0], args[1:]...) 29 cmd.Stdout = os.Stdout 30 cmd.Stderr = os.Stderr 31 return cmd.Run() 32 } 33 34 // execCompose runs a Docker Compose command for a testnet. 35 func execCompose(dir string, args ...string) error { 36 return exec(append( 37 []string{"docker-compose", "-f", filepath.Join(dir, "docker-compose.yml")}, 38 args...)...) 39 } 40 41 // execComposeVerbose runs a Docker Compose command for a testnet and displays its output. 42 func execComposeVerbose(dir string, args ...string) error { 43 return execVerbose(append( 44 []string{"docker-compose", "-f", filepath.Join(dir, "docker-compose.yml")}, 45 args...)...) 46 } 47 48 // execDocker runs a Docker command. 49 func execDocker(args ...string) error { 50 return exec(append([]string{"docker"}, args...)...) 51 }