add pip command and fix error codes on all commands
This commit is contained in:
parent
e6ff94c45f
commit
4e2c314c2c
3 changed files with 35 additions and 10 deletions
|
@ -25,13 +25,9 @@ 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 strings.Trim(string(outputBytes), "\n"), nil
|
||||
|
||||
|
|
33
cmd/pip.go
Normal file
33
cmd/pip.go
Normal file
|
@ -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
|
||||
|
||||
}
|
|
@ -25,13 +25,9 @@ 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 strings.Trim(string(outputBytes), "\n"), nil
|
||||
|
||||
|
|
Loading…
Reference in a new issue