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