-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
116 lines (101 loc) · 2.33 KB
/
driver.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"fmt"
"log"
"os"
ion "github.com/fixstars/ion-go"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "ion-go-driver",
Usage: "The driver interface for ion-go",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "with-bb-module",
Usage: "Specify path to building block list.",
},
},
Commands: []*cli.Command{
{
Name: "compile",
Usage: "Compile ion graph into static library and header.",
Action: func(c *cli.Context) error {
graph := c.Path("graph")
modules := c.StringSlice("with-bb-module")
funcName := c.String("func-name")
outputDirectory := c.String("output-directory")
b, err := ion.NewBuilder()
if err != nil {
return err
}
var f *os.File
if f, err = os.Open(graph); err != nil {
return err
}
defer f.Close()
if err = b.LoadFromReader(f); err != nil {
return err
}
for _, m := range modules {
if err = b.WithBBModule(m); err != nil {
return err
}
}
if err = b.Compile(funcName, &ion.CompileOption{OutputDirectory: outputDirectory}); err != nil {
return err
}
return nil
},
Flags: []cli.Flag{
&cli.PathFlag{
Name: "graph",
Usage: "Specify graph path to be built.",
Required: true,
},
&cli.StringFlag{
Name: "target",
Usage: "Specify target string for builder.",
DefaultText: "host",
},
&cli.StringFlag{
Name: "func-name",
Usage: "Specify func name to be built.",
Required: true,
},
&cli.StringFlag{
Name: "output-directory",
Usage: "Specify output directory.",
DefaultText: ".",
Required: true,
},
},
}, {
Name: "metadata",
Usage: "Retrieve metadata from building block.",
Action: func(c *cli.Context) error {
modules := c.StringSlice("with-bb-module")
b, err := ion.NewBuilder()
if err != nil {
return err
}
for _, m := range modules {
if err = b.WithBBModule(m); err != nil {
return err
}
}
var md string
if md, err = b.BBMetadata(); err != nil {
return err
}
fmt.Printf("%v", md)
return nil
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}