-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
58 lines (48 loc) · 1.14 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
// protoc-gen-sol by Celer Network Team
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"github.com/celer-network/pb3-gen-sol/generator"
"github.com/golang/protobuf/proto"
)
var showver = flag.Bool("v", false, "Show version and exit")
func main() {
flag.Parse()
if *showver {
printver()
os.Exit(0)
}
// Begin by allocating a generator. The request and response structures are stored there
// so we can do error handling easily - the response structure contains the field to
// report failure.
g := generator.New()
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
generator.Error(err, "reading input")
}
if err := proto.Unmarshal(data, g.Request); err != nil {
generator.Error(err, "parsing input proto")
}
g.ParseParams()
g.GenerateAllFiles()
// Send back the results.
data, err = proto.Marshal(g.Response)
if err != nil {
generator.Error(err, "failed to marshal output proto")
}
_, err = os.Stdout.Write(data)
if err != nil {
generator.Error(err, "failed to write output proto")
}
}
var (
version string
commit string
)
func printver() {
fmt.Println("Version:", version)
fmt.Println("Commit:", commit)
}