update which options

This commit is contained in:
Shane C 2024-07-09 18:53:22 -04:00
parent 5d646427bd
commit 991429a290
Signed by: shane
GPG key ID: E46B5FEA35B22FF9
5 changed files with 21 additions and 9 deletions

View file

@ -9,9 +9,13 @@ import (
var NodeNotFound = errors.New("nodejs not found")
func Node(args ...string) (output string, err error) {
func Node(options BasicOptions, args ...string) (output string, err error) {
if _, err := Which("node"); err != nil {
if _, err := Which("node", BasicOptions{
Env: options.Env,
Sources: options.Sources,
Cwd: options.Cwd,
}); err != nil {
if errors.Is(err, ErrNotFound) {
return "", NodeNotFound
} else {

View file

@ -7,9 +7,13 @@ import (
"strings"
)
func Pip(args ...string) (output string, err error) {
func Pip(options BasicOptions, args ...string) (output string, err error) {
if _, err := Which("python3"); err != nil {
if _, err := Which("python3", BasicOptions{
Env: options.Env,
Sources: options.Sources,
Cwd: options.Cwd,
}); err != nil {
if errors.Is(err, ErrNotFound) {
return "", PythonNotFound
} else {

View file

@ -9,9 +9,13 @@ import (
var PythonNotFound = errors.New("python not found")
func Python(args ...string) (output string, err error) {
func Python(options BasicOptions, args ...string) (output string, err error) {
if _, err := Which("python3"); err != nil {
if _, err := Which("python3", BasicOptions{
Env: options.Env,
Sources: options.Sources,
Cwd: options.Cwd,
}); err != nil {
if errors.Is(err, ErrNotFound) {
return "", PythonNotFound
} else {

View file

@ -9,13 +9,13 @@ import (
var ErrNotFound = errors.New("which: command not found")
type WhichOptions struct {
type BasicOptions struct {
Env map[string]string
Sources []string
Cwd string
}
func Which(cmd string, options WhichOptions) (dir string, err error) {
func Which(cmd string, options BasicOptions) (dir string, err error) {
var sourceCommand strings.Builder
for _, value := range options.Sources {

View file

@ -12,7 +12,7 @@ import (
func (cmd *LinuxCommand) isCommandExecutable(command string) (bool, error) {
whichOut, err := cmd2.Which(command, cmd2.WhichOptions{
whichOut, err := cmd2.Which(command, cmd2.BasicOptions{
Env: cmd.Options.Env,
Sources: cmd.Options.Sources,
Cwd: cmd.Options.Cwd,