-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubcommand_setup.go
129 lines (106 loc) · 3.76 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
//+build !test
package main
import (
"context"
"flag"
"fmt"
"os"
"runtime"
"github.com/google/subcommands"
)
// This file contains the boiler-plate for the subcommands.
// 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
}
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.
`
}
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 {
// UNCOMMENT 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
}
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
`
}
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
}
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.
`
}
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 {
// UNCOMMENT replicate(*p)
return subcommands.ExitSuccess
}
// Options which may be set via flags for the "version" subcommand.
type versionCmd struct {
verbose bool
}
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.
`
}
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 {
fmt.Fprintf(os.Stdout, "%s\n", "version 0.1")
if p.verbose {
fmt.Fprintf(os.Stdout, "Built with %s\n", runtime.Version())
}
return subcommands.ExitSuccess
}