diff --git a/etcdctl/ctlv2/command/auth_commands.go b/etcdctl/ctlv2/command/auth_commands.go index d0bef6490..96a17738f 100644 --- a/etcdctl/ctlv2/command/auth_commands.go +++ b/etcdctl/ctlv2/command/auth_commands.go @@ -44,12 +44,14 @@ func NewAuthCommands() cli.Command { } } -func actionAuthEnable(c *cli.Context) { +func actionAuthEnable(c *cli.Context) error { authEnableDisable(c, true) + return nil } -func actionAuthDisable(c *cli.Context) { +func actionAuthDisable(c *cli.Context) error { authEnableDisable(c, false) + return nil } func mustNewAuthAPI(c *cli.Context) client.AuthAPI { diff --git a/etcdctl/ctlv2/command/backup_command.go b/etcdctl/ctlv2/command/backup_command.go index 9f6beaa48..c83761a15 100644 --- a/etcdctl/ctlv2/command/backup_command.go +++ b/etcdctl/ctlv2/command/backup_command.go @@ -46,7 +46,7 @@ func NewBackupCommand() cli.Command { } // handleBackup handles a request that intends to do a backup. -func handleBackup(c *cli.Context) { +func handleBackup(c *cli.Context) error { var srcWAL string var destWAL string @@ -113,4 +113,6 @@ func handleBackup(c *cli.Context) { if err := neww.SaveSnapshot(walsnap); err != nil { log.Fatal(err) } + + return nil } diff --git a/etcdctl/ctlv2/command/cluster_health.go b/etcdctl/ctlv2/command/cluster_health.go index f80d1e2c6..2ba347e7d 100644 --- a/etcdctl/ctlv2/command/cluster_health.go +++ b/etcdctl/ctlv2/command/cluster_health.go @@ -40,7 +40,7 @@ func NewClusterHealthCommand() cli.Command { } } -func handleClusterHealth(c *cli.Context) { +func handleClusterHealth(c *cli.Context) error { forever := c.Bool("forever") if forever { sigch := make(chan os.Signal, 1) @@ -125,9 +125,10 @@ func handleClusterHealth(c *cli.Context) { if !forever { if health { os.Exit(ExitSuccess) - } else { - os.Exit(ExitClusterNotHealthy) + return nil } + os.Exit(ExitClusterNotHealthy) + return nil } fmt.Printf("\nnext check after 10 second...\n\n") diff --git a/etcdctl/ctlv2/command/exec_watch_command.go b/etcdctl/ctlv2/command/exec_watch_command.go index cf2814c40..b23939a14 100644 --- a/etcdctl/ctlv2/command/exec_watch_command.go +++ b/etcdctl/ctlv2/command/exec_watch_command.go @@ -36,8 +36,9 @@ func NewExecWatchCommand() cli.Command { cli.IntFlag{Name: "after-index", Value: 0, Usage: "watch after the given index"}, cli.BoolFlag{Name: "recursive, r", Usage: "watch all values for key and child keys"}, }, - Action: func(c *cli.Context) { + Action: func(c *cli.Context) error { execWatchCommandFunc(c, mustNewKeyAPI(c)) + return nil }, } } diff --git a/etcdctl/ctlv2/command/get_command.go b/etcdctl/ctlv2/command/get_command.go index 04bdee5a3..9f99c8fcb 100644 --- a/etcdctl/ctlv2/command/get_command.go +++ b/etcdctl/ctlv2/command/get_command.go @@ -33,8 +33,9 @@ func NewGetCommand() cli.Command { cli.BoolFlag{Name: "sort", Usage: "returns result in sorted order"}, cli.BoolFlag{Name: "quorum, q", Usage: "require quorum for get request"}, }, - Action: func(c *cli.Context) { + Action: func(c *cli.Context) error { getCommandFunc(c, mustNewKeyAPI(c)) + return nil }, } } diff --git a/etcdctl/ctlv2/command/import_snap_command.go b/etcdctl/ctlv2/command/import_snap_command.go index 5f1d9cd47..4f1518093 100644 --- a/etcdctl/ctlv2/command/import_snap_command.go +++ b/etcdctl/ctlv2/command/import_snap_command.go @@ -48,7 +48,7 @@ func NewImportSnapCommand() cli.Command { } } -func handleImportSnap(c *cli.Context) { +func handleImportSnap(c *cli.Context) error { d, err := ioutil.ReadFile(c.String("snap")) if err != nil { if c.String("snap") == "" { @@ -87,6 +87,7 @@ func handleImportSnap(c *cli.Context) { close(setc) wg.Wait() fmt.Printf("finished importing %d keys\n", n) + return nil } func copyKeys(n *store.NodeExtern, setc chan set) int { diff --git a/etcdctl/ctlv2/command/ls_command.go b/etcdctl/ctlv2/command/ls_command.go index 044f3218a..2c43256fc 100644 --- a/etcdctl/ctlv2/command/ls_command.go +++ b/etcdctl/ctlv2/command/ls_command.go @@ -32,8 +32,9 @@ func NewLsCommand() cli.Command { cli.BoolFlag{Name: "p", Usage: "append slash (/) to directories"}, cli.BoolFlag{Name: "quorum, q", Usage: "require quorum for get request"}, }, - Action: func(c *cli.Context) { + Action: func(c *cli.Context) error { lsCommandFunc(c, mustNewKeyAPI(c)) + return nil }, } } diff --git a/etcdctl/ctlv2/command/member_commands.go b/etcdctl/ctlv2/command/member_commands.go index 7362b1d2a..84747873b 100644 --- a/etcdctl/ctlv2/command/member_commands.go +++ b/etcdctl/ctlv2/command/member_commands.go @@ -55,7 +55,7 @@ func NewMemberCommand() cli.Command { } } -func actionMemberList(c *cli.Context) { +func actionMemberList(c *cli.Context) error { if len(c.Args()) != 0 { fmt.Fprintln(os.Stderr, "No arguments accepted") os.Exit(1) @@ -86,9 +86,11 @@ func actionMemberList(c *cli.Context) { fmt.Printf("%s: name=%s peerURLs=%s clientURLs=%s isLeader=%v\n", m.ID, m.Name, strings.Join(m.PeerURLs, ","), strings.Join(m.ClientURLs, ","), isLeader) } } + + return nil } -func actionMemberAdd(c *cli.Context) { +func actionMemberAdd(c *cli.Context) error { args := c.Args() if len(args) != 2 { fmt.Fprintln(os.Stderr, "Provide a name and a single member peerURL") @@ -132,9 +134,10 @@ func actionMemberAdd(c *cli.Context) { fmt.Printf("ETCD_NAME=%q\n", newName) fmt.Printf("ETCD_INITIAL_CLUSTER=%q\n", strings.Join(conf, ",")) fmt.Printf("ETCD_INITIAL_CLUSTER_STATE=\"existing\"\n") + return nil } -func actionMemberRemove(c *cli.Context) { +func actionMemberRemove(c *cli.Context) error { args := c.Args() if len(args) != 1 { fmt.Fprintln(os.Stderr, "Provide a single member ID") @@ -177,9 +180,10 @@ func actionMemberRemove(c *cli.Context) { } fmt.Printf("Removed member %s from cluster\n", removalID) + return nil } -func actionMemberUpdate(c *cli.Context) { +func actionMemberUpdate(c *cli.Context) error { args := c.Args() if len(args) != 2 { fmt.Fprintln(os.Stderr, "Provide an ID and a list of comma separated peerURL (0xabcd http://example.com,http://example1.com)") @@ -199,4 +203,5 @@ func actionMemberUpdate(c *cli.Context) { } fmt.Printf("Updated member with ID %s in cluster\n", mid) + return nil } diff --git a/etcdctl/ctlv2/command/mk_command.go b/etcdctl/ctlv2/command/mk_command.go index d915e45b2..aeb40933b 100644 --- a/etcdctl/ctlv2/command/mk_command.go +++ b/etcdctl/ctlv2/command/mk_command.go @@ -33,8 +33,9 @@ func NewMakeCommand() cli.Command { cli.BoolFlag{Name: "in-order", Usage: "create in-order key under directory "}, cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live"}, }, - Action: func(c *cli.Context) { + Action: func(c *cli.Context) error { mkCommandFunc(c, mustNewKeyAPI(c)) + return nil }, } } diff --git a/etcdctl/ctlv2/command/mkdir_command.go b/etcdctl/ctlv2/command/mkdir_command.go index 86a410652..ec848bf11 100644 --- a/etcdctl/ctlv2/command/mkdir_command.go +++ b/etcdctl/ctlv2/command/mkdir_command.go @@ -31,8 +31,9 @@ func NewMakeDirCommand() cli.Command { Flags: []cli.Flag{ cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live"}, }, - Action: func(c *cli.Context) { + Action: func(c *cli.Context) error { mkdirCommandFunc(c, mustNewKeyAPI(c), client.PrevNoExist) + return nil }, } } diff --git a/etcdctl/ctlv2/command/rm_command.go b/etcdctl/ctlv2/command/rm_command.go index 6e4ab119d..c4941c364 100644 --- a/etcdctl/ctlv2/command/rm_command.go +++ b/etcdctl/ctlv2/command/rm_command.go @@ -33,8 +33,9 @@ func NewRemoveCommand() cli.Command { cli.StringFlag{Name: "with-value", Value: "", Usage: "previous value"}, cli.IntFlag{Name: "with-index", Value: 0, Usage: "previous index"}, }, - Action: func(c *cli.Context) { + Action: func(c *cli.Context) error { rmCommandFunc(c, mustNewKeyAPI(c)) + return nil }, } } diff --git a/etcdctl/ctlv2/command/rmdir_command.go b/etcdctl/ctlv2/command/rmdir_command.go index 62800bb8f..1078ee87a 100644 --- a/etcdctl/ctlv2/command/rmdir_command.go +++ b/etcdctl/ctlv2/command/rmdir_command.go @@ -27,8 +27,9 @@ func NewRemoveDirCommand() cli.Command { Name: "rmdir", Usage: "removes the key if it is an empty directory or a key-value pair", ArgsUsage: "", - Action: func(c *cli.Context) { + Action: func(c *cli.Context) error { rmdirCommandFunc(c, mustNewKeyAPI(c)) + return nil }, } } diff --git a/etcdctl/ctlv2/command/role_commands.go b/etcdctl/ctlv2/command/role_commands.go index 0c3bab7dc..65c68eb59 100644 --- a/etcdctl/ctlv2/command/role_commands.go +++ b/etcdctl/ctlv2/command/role_commands.go @@ -92,7 +92,7 @@ func mustNewAuthRoleAPI(c *cli.Context) client.AuthRoleAPI { return client.NewAuthRoleAPI(hc) } -func actionRoleList(c *cli.Context) { +func actionRoleList(c *cli.Context) error { if len(c.Args()) != 0 { fmt.Fprintln(os.Stderr, "No arguments accepted") os.Exit(1) @@ -109,9 +109,11 @@ func actionRoleList(c *cli.Context) { for _, role := range roles { fmt.Printf("%s\n", role) } + + return nil } -func actionRoleAdd(c *cli.Context) { +func actionRoleAdd(c *cli.Context) error { api, role := mustRoleAPIAndName(c) ctx, cancel := contextWithTotalTimeout(c) defer cancel() @@ -128,9 +130,10 @@ func actionRoleAdd(c *cli.Context) { } fmt.Printf("Role %s created\n", role) + return nil } -func actionRoleRemove(c *cli.Context) { +func actionRoleRemove(c *cli.Context) error { api, role := mustRoleAPIAndName(c) ctx, cancel := contextWithTotalTimeout(c) err := api.RemoveRole(ctx, role) @@ -141,14 +144,17 @@ func actionRoleRemove(c *cli.Context) { } fmt.Printf("Role %s removed\n", role) + return nil } -func actionRoleGrant(c *cli.Context) { +func actionRoleGrant(c *cli.Context) error { roleGrantRevoke(c, true) + return nil } -func actionRoleRevoke(c *cli.Context) { +func actionRoleRevoke(c *cli.Context) error { roleGrantRevoke(c, false) + return nil } func roleGrantRevoke(c *cli.Context, grant bool) { @@ -214,7 +220,7 @@ func roleGrantRevoke(c *cli.Context, grant bool) { fmt.Printf("Role %s updated\n", role) } -func actionRoleGet(c *cli.Context) { +func actionRoleGet(c *cli.Context) error { api, rolename := mustRoleAPIAndName(c) ctx, cancel := contextWithTotalTimeout(c) @@ -233,6 +239,7 @@ func actionRoleGet(c *cli.Context) { for _, v := range role.Permissions.KV.Write { fmt.Printf("\t%s\n", v) } + return nil } func mustRoleAPIAndName(c *cli.Context) (client.AuthRoleAPI, string) { diff --git a/etcdctl/ctlv2/command/set_command.go b/etcdctl/ctlv2/command/set_command.go index 807d73e2c..c9d332c39 100644 --- a/etcdctl/ctlv2/command/set_command.go +++ b/etcdctl/ctlv2/command/set_command.go @@ -40,8 +40,9 @@ func NewSetCommand() cli.Command { cli.StringFlag{Name: "swap-with-value", Value: "", Usage: "previous value"}, cli.IntFlag{Name: "swap-with-index", Value: 0, Usage: "previous index"}, }, - Action: func(c *cli.Context) { + Action: func(c *cli.Context) error { setCommandFunc(c, mustNewKeyAPI(c)) + return nil }, } } diff --git a/etcdctl/ctlv2/command/set_dir_command.go b/etcdctl/ctlv2/command/set_dir_command.go index 8d743d313..b770684e2 100644 --- a/etcdctl/ctlv2/command/set_dir_command.go +++ b/etcdctl/ctlv2/command/set_dir_command.go @@ -28,8 +28,9 @@ func NewSetDirCommand() cli.Command { Flags: []cli.Flag{ cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live"}, }, - Action: func(c *cli.Context) { + Action: func(c *cli.Context) error { mkdirCommandFunc(c, mustNewKeyAPI(c), client.PrevIgnore) + return nil }, } } diff --git a/etcdctl/ctlv2/command/update_command.go b/etcdctl/ctlv2/command/update_command.go index c6e7d2bd6..947eaa922 100644 --- a/etcdctl/ctlv2/command/update_command.go +++ b/etcdctl/ctlv2/command/update_command.go @@ -32,8 +32,9 @@ func NewUpdateCommand() cli.Command { Flags: []cli.Flag{ cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live"}, }, - Action: func(c *cli.Context) { + Action: func(c *cli.Context) error { updateCommandFunc(c, mustNewKeyAPI(c)) + return nil }, } } diff --git a/etcdctl/ctlv2/command/update_dir_command.go b/etcdctl/ctlv2/command/update_dir_command.go index 34c0093f1..cdb9333b9 100644 --- a/etcdctl/ctlv2/command/update_dir_command.go +++ b/etcdctl/ctlv2/command/update_dir_command.go @@ -31,8 +31,9 @@ func NewUpdateDirCommand() cli.Command { Flags: []cli.Flag{ cli.IntFlag{Name: "ttl", Value: 0, Usage: "key time-to-live"}, }, - Action: func(c *cli.Context) { + Action: func(c *cli.Context) error { updatedirCommandFunc(c, mustNewKeyAPI(c)) + return nil }, } } diff --git a/etcdctl/ctlv2/command/user_commands.go b/etcdctl/ctlv2/command/user_commands.go index f385ff34a..78224eb8d 100644 --- a/etcdctl/ctlv2/command/user_commands.go +++ b/etcdctl/ctlv2/command/user_commands.go @@ -87,7 +87,7 @@ func mustNewAuthUserAPI(c *cli.Context) client.AuthUserAPI { return client.NewAuthUserAPI(hc) } -func actionUserList(c *cli.Context) { +func actionUserList(c *cli.Context) error { if len(c.Args()) != 0 { fmt.Fprintln(os.Stderr, "No arguments accepted") os.Exit(1) @@ -104,9 +104,10 @@ func actionUserList(c *cli.Context) { for _, user := range users { fmt.Printf("%s\n", user) } + return nil } -func actionUserAdd(c *cli.Context) { +func actionUserAdd(c *cli.Context) error { api, userarg := mustUserAPIAndName(c) ctx, cancel := contextWithTotalTimeout(c) defer cancel() @@ -129,9 +130,10 @@ func actionUserAdd(c *cli.Context) { } fmt.Printf("User %s created\n", user) + return nil } -func actionUserRemove(c *cli.Context) { +func actionUserRemove(c *cli.Context) error { api, user := mustUserAPIAndName(c) ctx, cancel := contextWithTotalTimeout(c) err := api.RemoveUser(ctx, user) @@ -142,9 +144,10 @@ func actionUserRemove(c *cli.Context) { } fmt.Printf("User %s removed\n", user) + return nil } -func actionUserPasswd(c *cli.Context) { +func actionUserPasswd(c *cli.Context) error { api, user := mustUserAPIAndName(c) ctx, cancel := contextWithTotalTimeout(c) defer cancel() @@ -166,14 +169,17 @@ func actionUserPasswd(c *cli.Context) { } fmt.Printf("Password updated\n") + return nil } -func actionUserGrant(c *cli.Context) { +func actionUserGrant(c *cli.Context) error { userGrantRevoke(c, true) + return nil } -func actionUserRevoke(c *cli.Context) { +func actionUserRevoke(c *cli.Context) error { userGrantRevoke(c, false) + return nil } func userGrantRevoke(c *cli.Context, grant bool) { @@ -207,7 +213,7 @@ func userGrantRevoke(c *cli.Context, grant bool) { fmt.Printf("User %s updated\n", user) } -func actionUserGet(c *cli.Context) { +func actionUserGet(c *cli.Context) error { api, username := mustUserAPIAndName(c) ctx, cancel := contextWithTotalTimeout(c) user, err := api.GetUser(ctx, username) @@ -218,7 +224,7 @@ func actionUserGet(c *cli.Context) { } fmt.Printf("User: %s\n", user.User) fmt.Printf("Roles: %s\n", strings.Join(user.Roles, " ")) - + return nil } func mustUserAPIAndName(c *cli.Context) (client.AuthUserAPI, string) { diff --git a/etcdctl/ctlv2/command/watch_command.go b/etcdctl/ctlv2/command/watch_command.go index cc1fc31c5..93fcf6714 100644 --- a/etcdctl/ctlv2/command/watch_command.go +++ b/etcdctl/ctlv2/command/watch_command.go @@ -36,8 +36,9 @@ func NewWatchCommand() cli.Command { cli.IntFlag{Name: "after-index", Value: 0, Usage: "watch after the given index"}, cli.BoolFlag{Name: "recursive, r", Usage: "returns all values for key and child keys"}, }, - Action: func(c *cli.Context) { + Action: func(c *cli.Context) error { watchCommandFunc(c, mustNewKeyAPI(c)) + return nil }, } }