forked from sensu/sensu-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
member-update.go
40 lines (33 loc) · 990 Bytes
/
member-update.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
package cluster
import (
"errors"
"fmt"
"strconv"
"github.com/sensu/sensu-go/cli"
"github.com/spf13/cobra"
)
// MemberUpdateCommand updates a cluster member
func MemberUpdateCommand(cli *cli.SensuCli) *cobra.Command {
return &cobra.Command{
Use: "member-update [ID] [PEER_ADDRS]",
Short: "update cluster member by ID with comma-separated peer addresses",
SilenceUsage: false,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 2 {
_ = cmd.Help()
return errors.New("invalid argument(s) received")
}
memberID := args[0]
peerAddrs := splitAndTrim(args[1])
id, err := strconv.ParseUint(memberID, 16, 64)
if err != nil {
return fmt.Errorf("invalid id: %s", err)
}
if _, err := cli.Client.MemberUpdate(id, peerAddrs); err != nil {
return fmt.Errorf("error updating cluster member: %s", err)
}
fmt.Fprintf(cmd.OutOrStdout(), "Updated member with ID %x in cluster\n", id)
return nil
},
}
}