-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathutil.go
More file actions
55 lines (48 loc) · 1.06 KB
/
util.go
File metadata and controls
55 lines (48 loc) · 1.06 KB
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 yaakcli
import (
"os"
"path"
"runtime"
"strings"
)
func writeFile(writePath, contents string) {
CheckError(os.MkdirAll(path.Dir(writePath), 0755))
CheckError(os.WriteFile(writePath, []byte(contents), 0755))
}
func readFile(path string) string {
pkgBytes, err := TemplateFS.ReadFile(path)
CheckError(err)
return string(pkgBytes)
}
func copyFile(relPath, dstDir, name string) {
contents := readFile(path.Join("template", relPath))
contents = strings.ReplaceAll(contents, "yaak-plugin-name", name)
writeFile(path.Join(dstDir, relPath), contents)
}
func fileExists(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
return false
}
return true
}
func prodStagingDevStr(prod, staging, dev string) string {
if os.Getenv("ENVIRONMENT") == "staging" {
return staging
} else if os.Getenv("ENVIRONMENT") == "development" {
return dev
} else {
return prod
}
}
func GetUAPlatform() string {
switch runtime.GOOS {
case "windows":
return "Win"
case "darwin":
return "Mac"
case "linux":
return "Linux"
default:
return "Unknown"
}
}