-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (43 loc) · 931 Bytes
/
main.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
package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"github.com/omarahm3/compat/compat"
)
const (
COMPAT_FILE = "compat"
)
func main() {
path, err := os.Getwd()
must(err)
filePath, err := getCompatFilePath(path)
must(err)
content := readFile(*filePath)
err = compat.Run(content)
must(err)
}
func getCompatFilePath(cwd string) (*string, error) {
ymlFile := fmt.Sprintf("%s/%s.yml", cwd, COMPAT_FILE)
yamlFile := fmt.Sprintf("%s/%s.yaml", cwd, COMPAT_FILE)
if _, err := os.Stat(ymlFile); !os.IsNotExist(err) {
return &ymlFile, nil
}
if _, err := os.Stat(yamlFile); !os.IsNotExist(err) {
return &yamlFile, nil
}
return nil, errors.New("Compat file was not found. Please consider creating one.")
}
func readFile(file string) []byte {
content, err := ioutil.ReadFile(file)
must(err)
return content
}
func must(err error) {
if err == nil {
return
}
fmt.Println(err.Error())
os.Exit(1)
}