-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathutil.go
76 lines (63 loc) · 1.31 KB
/
util.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package cli
import (
"fmt"
"io/ioutil"
"log"
"github.com/spf13/cobra"
)
var LoggingEnabled = false
var PrintingDisabled = false
var GithubToken = ""
type Args interface {
SetArgs(args []string)
}
func RunArgs[T Args](f func(cmd *cobra.Command, args T) error, call T) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error { call.SetArgs(args); return f(cmd, call) }
}
func getSharedObjectExt(os string) string {
if os == "darwin" || os == "macos" {
return "dylib"
} else if os == "windows" {
return "dll"
} else {
return "so"
}
}
func getSharedObjectFileName(os string) string {
if os == "windows" {
return "extism." + getSharedObjectExt(os)
} else {
return "libextism." + getSharedObjectExt(os)
}
}
func getStaticLibFileName(os string) string {
if os == "windows" {
return "extism.lib"
} else {
return "libextism.a"
}
}
func copyFile(src string, dest string) error {
Print("Copying", src, "to", dest)
bytesRead, err := ioutil.ReadFile(src)
if err != nil {
return err
}
err = ioutil.WriteFile(dest, bytesRead, 0755)
if err != nil {
return err
}
return nil
}
func Log(s ...any) {
if LoggingEnabled {
log.Println(s...)
}
}
func Print(s ...any) {
if LoggingEnabled {
Log(s...)
} else if !PrintingDisabled {
fmt.Println(s...)
}
}