forked from ForceCLI/force
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
54 lines (46 loc) · 947 Bytes
/
config.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
package main
import (
"github.com/ddollar/config"
"os"
"path/filepath"
"strings"
//"fmt"
)
var Config = config.NewConfig("force")
func GetSourceDir() (src string, err error) {
// Last element is default
var sourceDirs = []string{
//"src",
"metadata",
}
wd, err := os.Getwd()
err = nil
for _, src = range sourceDirs {
if strings.Contains(wd, src) {
// our working directory contains a src dir above us, we need to move up the file syste
nsrc := wd
for {
nsrc = filepath.Dir(nsrc)
if filepath.Base(nsrc) == src {
src = nsrc
return
}
}
} else {
_, err = os.Stat(filepath.Join(wd, src)) //, "package.xml"))
// Found a real source dir
if err == nil {
return
}
}
}
return
}
func ExitIfNoSourceDir(err error) {
if err != nil {
if os.IsNotExist(err) {
ErrorAndExit("Current directory does not contain a metadata or src directory")
}
ErrorAndExit(err.Error())
}
}