forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
85 lines (78 loc) · 1.58 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Command ndndpdk-ctrl controls the NDN-DPDK service.
package main
import (
"log"
"os"
"sort"
"github.com/urfave/cli/v2"
"github.com/usnistgov/ndn-dpdk/core/gqlclient"
"github.com/usnistgov/ndn-dpdk/core/version"
)
var (
cmdout bool
gqlCfg gqlclient.Config
client *gqlclient.Client
)
var app = &cli.App{
Version: version.V.String(),
Usage: "Control NDN-DPDK service.",
EnableBashCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "gqlserver",
Usage: "GraphQL `endpoint` of NDN-DPDK service",
Value: "http://127.0.0.1:3030/",
Destination: &gqlCfg.HTTPUri,
},
&cli.BoolFlag{
Name: "cmdout",
Usage: "print command line instead of running the command",
Value: false,
Destination: &cmdout,
},
},
Before: func(*cli.Context) (e error) {
if e := gqlCfg.Validate(); e != nil {
return e
}
if !cmdout {
client, e = gqlclient.New(gqlCfg)
}
return e
},
After: func(*cli.Context) (e error) {
if client != nil {
e = client.Close()
client = nil
}
return e
},
}
func defineCommand(command *cli.Command) {
app.Commands = append(app.Commands, command)
}
func main() {
sort.Sort(cli.CommandsByName(app.Commands))
e := app.Run(os.Args)
if e != nil {
log.Fatal(e)
}
}
func init() {
defineCommand(&cli.Command{
Name: "show-version",
Usage: "Show daemon version",
Action: func(c *cli.Context) error {
return clientDoPrint(c.Context, `
query version {
version {
version
commit
date
dirty
}
}
`, nil, "version")
},
})
}