forked from joelnb/xenstore-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
108 lines (100 loc) · 2.1 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"fmt"
"log"
"os"
"time"
xenstore "github.com/joelnb/xenstore-go"
"github.com/urfave/cli"
)
var client *xenstore.Client
func main() {
app := &cli.App{
Usage: "XenStore tools in Go",
Version: Version,
Compiled: time.Now(),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "socket-path",
Usage: "Path to the xenstore unix socket",
},
&cli.StringFlag{
Name: "xenbus-path",
Usage: "Path to the xenbus device",
},
&cli.BoolFlag{
Name: "use-socket, s",
Usage: "Use the socket rather than the xenbus device",
},
},
Before: func(ctx *cli.Context) error {
t, err := getTransport(ctx)
if err != nil {
// Returning an error here causes usage text to be printed so just exit instead
fmt.Println(err)
os.Exit(2)
}
client = xenstore.NewClient(t)
return nil
},
After: func(ctx *cli.Context) error {
if client != nil {
client.Close()
}
return client.Error()
},
Commands: []cli.Command{
cli.Command{
Name: "read",
Flags: []cli.Flag{},
Usage: "Read values from xenstore by path",
Action: ReadCommand,
},
cli.Command{
Name: "write",
Flags: []cli.Flag{},
Usage: "Write values to xenstore by path",
Action: WriteCommand,
},
cli.Command{
Name: "rm",
Flags: []cli.Flag{},
Usage: "Remove a value from xenstore by path",
Action: RmCommand,
},
cli.Command{
Name: "list",
Aliases: []string{"ls"},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "long, l",
},
},
Usage: "List values from xenstore by path",
Action: ListCommand,
},
cli.Command{
Name: "vm-path",
Flags: []cli.Flag{},
Usage: "Get the path for a VM",
Action: VMPathCommand,
},
cli.Command{
Name: "watch",
Flags: []cli.Flag{},
Usage: "Watch a XenStore path for changes",
Action: WatchCommand,
},
cli.Command{
Name: "info",
Flags: []cli.Flag{},
Usage: "Display system information",
Action: InfoCommand,
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}