@@ -11,12 +11,10 @@ import (
11
11
)
12
12
13
13
var (
14
- client * memClient
15
- host * string
16
- port * string
17
- path * string
18
- backup * bool
19
- restore * bool
14
+ client * memClient
15
+ addr * string
16
+ path * string
17
+ operation * string
20
18
21
19
format = logging .MustStringFormatter (
22
20
`%{color}%{time:2006-01-02T15:04:05.999999} %{shortfunc} ▶ %{level:.8s} %{id:03x}%{color:reset} %{message}` ,
@@ -37,11 +35,9 @@ func init() {
37
35
// Set the backend to be used.
38
36
logging .SetBackend (backendLevelFormatted )
39
37
40
- host = flag .String ("host" , `0.0.0.0` , "Memcached hostname" )
41
- port = flag .String ("port" , "11211" , "Memcached port" )
42
- path = flag .String ("name" , "mem_backup.json" , "Path to store the output file at" )
43
- backup = flag .Bool ("backup" , false , "Whether to backup the cache" )
44
- restore = flag .Bool ("restore" , false , "Whether to restore the cache" )
38
+ addr = flag .String ("addr" , `localhost:11211` , "Address to memcached server" )
39
+ path = flag .String ("filename" , "mem_backup.json" , "Path to store the output file at" )
40
+ operation = flag .String ("op" , "" , "Whether to backup the cache" )
45
41
46
42
// If the given filename does not have the suffix, add to it
47
43
* path = strings .Trim (* path , "/" )
@@ -51,7 +47,7 @@ func init() {
51
47
52
48
flag .Parse ()
53
49
54
- client = createClient (host , port )
50
+ client = createClient (addr )
55
51
}
56
52
57
53
// backupCache: Exports the cache into file at the given path
@@ -110,18 +106,14 @@ func restoreCache() {
110
106
111
107
// main: Validates the arguments and processes backup or restore
112
108
func main () {
113
- Logger .Infof ("host %s" , * host )
114
- Logger .Infof ("port %s" , * port )
109
+ Logger .Infof ("address %s" , * addr )
115
110
116
- // If both the options are given or none of the options are given
117
- if (* backup && * restore ) || (! * backup && ! * restore ) {
118
- Logger .Error ("Exactly one option --backup or --restore is required" )
119
- os .Exit (1 )
120
- }
121
-
122
- if * backup {
111
+ if * operation == "backup" {
123
112
backupCache ()
124
- } else if * restore {
113
+ } else if * operation == " restore" {
125
114
restoreCache ()
115
+ } else {
116
+ Logger .Error ("--op is required with either 'backup' or 'restore'" )
117
+ os .Exit (1 )
126
118
}
127
119
}
0 commit comments