github.com/osievert/jfrog-cli-core@v1.2.7/artifactory/utils/pip/pip.go (about)

     1  package pip
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"github.com/jfrog/jfrog-client-go/utils/errorutils"
     7  	"github.com/jfrog/jfrog-client-go/utils/log"
     8  	"io"
     9  	"os/exec"
    10  )
    11  
    12  // Get executable path.
    13  // If run inside a virtual-env, this should return the path for the correct executable.
    14  func GetExecutablePath(executableName string) (string, error) {
    15  	executablePath, err := exec.LookPath(executableName)
    16  	if err != nil {
    17  		return "", errorutils.CheckError(err)
    18  	}
    19  
    20  	if executablePath == "" {
    21  		return "", errorutils.CheckError(errors.New(fmt.Sprintf("Could not find '%s' executable", executableName)))
    22  	}
    23  
    24  	log.Debug(fmt.Sprintf("Found %s executable at: %s", executableName, executablePath))
    25  	return executablePath, nil
    26  }
    27  
    28  func (pc *PipCmd) GetCmd() *exec.Cmd {
    29  	var cmd []string
    30  	cmd = append(cmd, pc.Executable)
    31  	cmd = append(cmd, pc.Command)
    32  	cmd = append(cmd, pc.CommandArgs...)
    33  	return exec.Command(cmd[0], cmd[1:]...)
    34  }
    35  
    36  func (pc *PipCmd) GetEnv() map[string]string {
    37  	return pc.EnvVars
    38  }
    39  
    40  func (pc *PipCmd) GetStdWriter() io.WriteCloser {
    41  	return pc.StrWriter
    42  }
    43  
    44  func (pc *PipCmd) GetErrWriter() io.WriteCloser {
    45  	return pc.ErrWriter
    46  }
    47  
    48  type PipCmd struct {
    49  	Executable  string
    50  	Command     string
    51  	CommandArgs []string
    52  	EnvVars     map[string]string
    53  	StrWriter   io.WriteCloser
    54  	ErrWriter   io.WriteCloser
    55  }