-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsubcommand_setup.go
171 lines (147 loc) · 4.04 KB
/
subcommand_setup.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//+build !test
package main
import (
"context"
"flag"
"github.com/google/subcommands"
)
//
// This file contains the boiler-plate for the subcommands.
//
// It is deliberately setup into a single file, which is excluded
// from the tests via the magic-comment at the top of the file,
// so that unit-test and test-coverage statistics do not include
// this code - which cannot meaningfully be tested.
//
//
// Options which may be set via flags for the "api-server" subcommand.
//
type apiServerCmd struct {
host string
blob string
dport int
uport int
dump bool
verbose bool
}
//
// Glue
//
func (*apiServerCmd) Name() string { return "api-server" }
func (*apiServerCmd) Synopsis() string { return "Launch an API-server." }
func (*apiServerCmd) Usage() string {
return `API-server :
Launch an API-server to handle the upload/download of objects.
`
}
//
// Flag setup
//
func (p *apiServerCmd) SetFlags(f *flag.FlagSet) {
f.StringVar(&p.host, "api-host", "0.0.0.0", "The IP to listen upon.")
f.StringVar(&p.blob, "blob-server", "", "Comma-separated list of blob-servers to contact.")
f.IntVar(&p.dport, "download-port", 9992, "The port to bind upon for downloading objects.")
f.IntVar(&p.uport, "upload-port", 9991, "The port to bind upon for uploading objects.")
f.BoolVar(&p.dump, "dump", false, "Dump configuration and exit?")
f.BoolVar(&p.verbose, "verbose", false, "Show more output from the API-server.")
}
//
// Entry-point - pass control to the API-server setup function.
//
func (p *apiServerCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
apiServer(*p)
return subcommands.ExitSuccess
}
//
// Options which may be set via flags for the "blob-server" subcommand.
//
type blobServerCmd struct {
store string
port int
host string
}
//
// Glue
//
func (*blobServerCmd) Name() string { return "blob-server" }
func (*blobServerCmd) Synopsis() string { return "Launch a blob-server." }
func (*blobServerCmd) Usage() string {
return `blob-server :
Launch a blob-server to handle the back-end storage
`
}
//
// Flag setup
//
func (p *blobServerCmd) SetFlags(f *flag.FlagSet) {
f.StringVar(&p.host, "host", "127.0.0.1", "The IP to listen upon")
f.IntVar(&p.port, "port", 3001, "The port to bind upon")
f.StringVar(&p.store, "store", "data", "The location to write the data to")
}
//
// Entry-point.
//
func (p *blobServerCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
blobServer(*p)
return subcommands.ExitSuccess
}
//
// Options which may be set via flags for the "replicate" subcommand.
//
type replicateCmd struct {
blob string
verbose bool
}
//
// Glue
//
func (*replicateCmd) Name() string { return "replicate" }
func (*replicateCmd) Synopsis() string { return "Trigger replication." }
func (*replicateCmd) Usage() string {
return `replication :
Trigger a single run of the replication/balancing operation.
`
}
//
// Flag setup
//
func (p *replicateCmd) SetFlags(f *flag.FlagSet) {
f.StringVar(&p.blob, "blob-server", "", "Comma-separated list of blob-servers to contact.")
f.BoolVar(&p.verbose, "verbose", false, "Be more verbose?")
}
//
// Entry-point - invoke the main replication-routine.
//
func (p *replicateCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
replicate(*p)
return subcommands.ExitSuccess
}
//
// Options which may be set via flags for the "version" subcommand.
//
type versionCmd struct {
verbose bool
}
//
// Glue
//
func (*versionCmd) Name() string { return "version" }
func (*versionCmd) Synopsis() string { return "Show our version." }
func (*versionCmd) Usage() string {
return `version :
Report upon our version, and exit.
`
}
//
// Flag setup
//
func (p *versionCmd) SetFlags(f *flag.FlagSet) {
f.BoolVar(&p.verbose, "verbose", false, "Show go version the binary was generated with.")
}
//
// Entry-point.
//
func (p *versionCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
showVersion(*p)
return subcommands.ExitSuccess
}