-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
62 lines (50 loc) · 1.11 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
package main
import (
"log"
"os"
"os/exec"
"strings"
)
func main() {
config, err := ReadConfig()
if err != nil {
log.Fatalf("Fatal error reading config file: %s\n", err)
}
protoc := GenProtoString(config)
if err := verifyDirectories(config); err != nil {
log.Fatalf("Could not create output directories: %v", err)
}
if config.Debug {
log.Printf("Executing protoc command: %v", protoc)
}
parts := strings.Split(strings.TrimSpace(protoc), " ")
cmd := exec.Command(parts[0], parts[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
log.Fatalf("Failed to execute protoc command: %v", err)
}
}
func verifyDirectories(config *Config) error {
if err := createDirIfMissing(config.Output); err != nil {
return err
}
for _, plugin := range config.Plugins {
if len(plugin.Output) > 0 {
if err := createDirIfMissing(plugin.Output); err != nil {
return err
}
}
}
return nil
}
func createDirIfMissing(path string) error {
if _, err := os.Stat(path); os.IsNotExist(err) {
err := os.MkdirAll(path, 0755)
if err != nil {
return err
}
}
return nil
}