-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (55 loc) · 1.36 KB
/
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
59
60
61
62
63
64
65
66
package main
import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
)
func detectRepoRootDirectory(wd string) (string, error) {
for ; wd != "/"; wd = filepath.Dir(wd) {
stat, _ := os.Stat(filepath.Join(wd, ".plzconfig"))
if stat.Mode().IsRegular() {
return wd, nil
}
}
return "", errors.New("the root directory not found")
}
func main() {
workingDirectory, err := os.Getwd()
if err != nil {
fmt.Printf("could not detect the working directory: %s\n", workingDirectory)
os.Exit(1)
}
if realWorkignDirectoryPath, err := os.Readlink(workingDirectory); err == nil {
workingDirectory = realWorkignDirectoryPath
}
rootDirectory, err := detectRepoRootDirectory(workingDirectory)
if err != nil {
fmt.Printf("could not detect .plzconfig: %s\n", err)
os.Exit(1)
}
err = os.Chdir(rootDirectory)
if err != nil {
fmt.Printf("could not change directory: %s\n", err)
os.Exit(1)
}
plzExec := PleaseRunner{}
config, err := plzExec.Config()
if err != nil {
fmt.Printf("could not read the Please config: %s\n", err)
os.Exit(1)
}
target := os.Args[1]
graph, err := plzExec.Graph(target)
if err != nil {
fmt.Printf("could not read the graph for: %s", err)
os.Exit(1)
}
transformer := Transformer{
RootDirectory: rootDirectory,
}
output := transformer.Transform(graph, config)
out, _ := json.Marshal(output)
fmt.Printf("%s", out)
}