-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
55 lines (48 loc) · 934 Bytes
/
path.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
53
54
55
package state
import (
"os"
"path/filepath"
)
const (
configFileName = ".runr.yaml"
secretFileName = ".runr.secrets"
)
func resolvePath(path string) string {
if path == "" || filepath.IsAbs(path) {
return path
}
return filepath.Join(
filepath.Dir(getDefaultConfigPath()),
path,
)
}
func getDefaultConfigPath() string {
if config := os.Getenv("RUNR_CONFIG"); config != "" {
return config
}
config := configWalkParents()
if config != "" {
return config
}
// use current working directory
return configFileName
}
func configWalkParents() string {
base, err := os.Getwd()
if err != nil {
return ""
}
for {
file := filepath.Join(base, configFileName)
if _, err := os.Stat(file); err == nil {
return file
}
base = filepath.Dir(base)
if base == "/" || base == "." || base == "" ||
base == string(filepath.Separator) ||
base == filepath.VolumeName(base) {
break
}
}
return ""
}