-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
there.go
37 lines (34 loc) · 801 Bytes
/
there.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
// package main contains the logic for the "there" command
package main
import (
"errors"
"log"
"os/exec"
"strings"
"github.com/oalders/is/types"
)
// Run "is there ...".
func (r *ThereCmd) Run(ctx *types.Context) error {
args := []string{"-c", "command -v " + r.Name}
cmd := exec.Command("sh", args...)
if ctx.Debug {
log.Printf("Running \"sh %s\"\n", strings.Join(args, " "))
}
err := cmd.Run()
if err != nil {
if ctx.Debug {
log.Printf("Error was: %v\n", err)
log.Printf("Running \"which %s\"\n", r.Name)
}
cmd := exec.Command("which", r.Name) //nolint:gosec
err := cmd.Run()
if err != nil {
if e := (&exec.ExitError{}); errors.As(err, &e) {
return nil
}
return errors.Join(errors.New("command run error"), err)
}
}
ctx.Success = true
return nil
}