forked from soarpenguin/redis-trib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
info.go
56 lines (47 loc) · 1.16 KB
/
info.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
package main
import (
"errors"
"fmt"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
// info host:port
var infoCommand = cli.Command{
Name: "info",
Usage: "display the info of redis cluster.",
ArgsUsage: `host:port`,
Description: `The info command get info from redis cluster.`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "password, a",
Value: "",
Usage: `password, the default value is ""`,
},
},
Action: func(context *cli.Context) error {
if context.NArg() != 1 {
fmt.Printf("Incorrect Usage.\n\n")
cli.ShowCommandHelp(context, "info")
logrus.Fatalf("Must provide host:port for info command!")
}
if context.String("password") != "" {
RedisPassword = context.String("password")
}
rt := NewRedisTrib()
if err := rt.InfoClusterCmd(context); err != nil {
return err
}
return nil
},
}
func (rt *RedisTrib) InfoClusterCmd(context *cli.Context) error {
var addr string
if addr = context.Args().Get(0); addr == "" {
return errors.New("please check host:port for info command")
}
if err := rt.LoadClusterInfoFromNode(addr); err != nil {
return err
}
rt.ShowClusterInfo()
return nil
}