forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
findbin.go
38 lines (31 loc) · 785 Bytes
/
findbin.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
38
package main
import (
"errors"
"os"
"os/exec"
"path/filepath"
"github.com/keybase/client/go/utils"
)
var errKeybaseNotFound = errors.New("failed to find the keybase binary")
// findKeybaseBinary returns the path to a Keybase binary, if it finds it.
func findKeybaseBinary(name string) (string, error) {
// Is it near the kbnm binary?
binPath, err := utils.BinPath()
if err == nil {
path := filepath.Join(filepath.Dir(binPath), name)
if _, err := os.Stat(path); !os.IsNotExist(err) {
return path, nil
}
}
// Is it in our PATH?
path, err := exec.LookPath(name)
if err == nil {
return path, nil
}
// Last ditch effort!
path = guessKeybasePath(name)
if _, err := os.Stat(path); !os.IsNotExist(err) {
return path, nil
}
return "", errKeybaseNotFound
}