diff --git a/cmd/node.go b/cmd/node.go index 2e57784..dc2d099 100644 --- a/cmd/node.go +++ b/cmd/node.go @@ -25,11 +25,7 @@ func Node(args ...string) (output string, err error) { if err != nil { var exitErr *exec.ExitError if errors.As(err, &exitErr) { - if exitErr.ExitCode() == 1 { - return "", ErrNotFound - } else { - return "", fmt.Errorf("command error: %w", err) - } + return "", fmt.Errorf("command error: %w", err) } } diff --git a/cmd/pip.go b/cmd/pip.go new file mode 100644 index 0000000..1dd3a01 --- /dev/null +++ b/cmd/pip.go @@ -0,0 +1,33 @@ +package cmd + +import ( + "errors" + "fmt" + "os/exec" + "strings" +) + +func Pip(args ...string) (output string, err error) { + + if _, err := Which("python3"); err != nil { + if errors.Is(err, ErrNotFound) { + return "", PythonNotFound + } else { + return "", err + } + } + + command := exec.Command("python3", "-m", "pip") + command.Args = append(command.Args, args...) + + outputBytes, err := command.Output() + if err != nil { + var exitErr *exec.ExitError + if errors.As(err, &exitErr) { + return "", fmt.Errorf("command error: %w", err) + } + } + + return strings.Trim(string(outputBytes), "\n"), nil + +} diff --git a/cmd/python.go b/cmd/python.go index b1ddc22..9592a67 100644 --- a/cmd/python.go +++ b/cmd/python.go @@ -25,11 +25,7 @@ func Python(args ...string) (output string, err error) { if err != nil { var exitErr *exec.ExitError if errors.As(err, &exitErr) { - if exitErr.ExitCode() == 1 { - return "", ErrNotFound - } else { - return "", fmt.Errorf("command error: %w", err) - } + return "", fmt.Errorf("command error: %w", err) } }