-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
52 lines (46 loc) · 834 Bytes
/
helpers.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package on_machine
import (
"os"
"os/exec"
)
// true if directory exists
func DirExists(path string) bool {
stat, err := os.Stat(path)
return err == nil && stat.IsDir()
}
// whether or not the user has a command on their $PATH
func commandExists(cmd string) bool {
_, err := exec.LookPath(cmd)
return err == nil
}
// path exists
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
// remove duplicates from a slice
func SliceUniqMap(s []string) []string {
seen := make(map[string]struct{}, len(s))
j := 0
for _, v := range s {
if _, ok := seen[v]; ok {
continue
}
seen[v] = struct{}{}
s[j] = v
j++
}
return s[:j]
}
func min(a, b int) int {
if a < b {
return a
}
return b
}