update which options
This commit is contained in:
parent
5d646427bd
commit
991429a290
5 changed files with 21 additions and 9 deletions
|
@ -9,9 +9,13 @@ import (
|
||||||
|
|
||||||
var NodeNotFound = errors.New("nodejs not found")
|
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) {
|
if errors.Is(err, ErrNotFound) {
|
||||||
return "", NodeNotFound
|
return "", NodeNotFound
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,9 +7,13 @@ import (
|
||||||
"strings"
|
"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) {
|
if errors.Is(err, ErrNotFound) {
|
||||||
return "", PythonNotFound
|
return "", PythonNotFound
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -9,9 +9,13 @@ import (
|
||||||
|
|
||||||
var PythonNotFound = errors.New("python not found")
|
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) {
|
if errors.Is(err, ErrNotFound) {
|
||||||
return "", PythonNotFound
|
return "", PythonNotFound
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -9,13 +9,13 @@ import (
|
||||||
|
|
||||||
var ErrNotFound = errors.New("which: command not found")
|
var ErrNotFound = errors.New("which: command not found")
|
||||||
|
|
||||||
type WhichOptions struct {
|
type BasicOptions struct {
|
||||||
Env map[string]string
|
Env map[string]string
|
||||||
Sources []string
|
Sources []string
|
||||||
Cwd 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
|
var sourceCommand strings.Builder
|
||||||
for _, value := range options.Sources {
|
for _, value := range options.Sources {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
func (cmd *LinuxCommand) isCommandExecutable(command string) (bool, error) {
|
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,
|
Env: cmd.Options.Env,
|
||||||
Sources: cmd.Options.Sources,
|
Sources: cmd.Options.Sources,
|
||||||
Cwd: cmd.Options.Cwd,
|
Cwd: cmd.Options.Cwd,
|
||||||
|
|
Loading…
Reference in a new issue