github.com/MagHErmit/tendermint@v0.282.1/test/e2e/runner/exec.go (about)

     1  // nolint: gosec
     2  package main
     3  
     4  import (
     5  	"fmt"
     6  	"os"
     7  	osexec "os/exec"
     8  	"path/filepath"
     9  )
    10  
    11  // execute executes a shell command.
    12  func exec(args ...string) error {
    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  	cmd := osexec.Command(args[0], args[1:]...)
    28  	cmd.Stdout = os.Stdout
    29  	cmd.Stderr = os.Stderr
    30  	return cmd.Run()
    31  }
    32  
    33  // execCompose runs a Docker Compose command for a testnet.
    34  func execCompose(dir string, args ...string) error {
    35  	return exec(append(
    36  		[]string{"docker-compose", "-f", filepath.Join(dir, "docker-compose.yml")},
    37  		args...)...)
    38  }
    39  
    40  // execComposeVerbose runs a Docker Compose command for a testnet and displays its output.
    41  func execComposeVerbose(dir string, args ...string) error {
    42  	return execVerbose(append(
    43  		[]string{"docker-compose", "-f", filepath.Join(dir, "docker-compose.yml")},
    44  		args...)...)
    45  }
    46  
    47  // execDocker runs a Docker command.
    48  func execDocker(args ...string) error {
    49  	return exec(append([]string{"docker"}, args...)...)
    50  }