etcdctl: tighten up output, reorganize README.md

Documentation was far too repetitive, making it a chore to read and
make changes. All commands are now organized by functionality and all
repetitive bits about return values and output are in a generalized
subsections.

etcdctl's output handling was missing a lot of commands. Similarly,
in many cases an output format could be given but fail to report
an error as expected.
This commit is contained in:
Anthony Romano
2016-12-12 17:03:09 -08:00
parent d9e928de7a
commit 780d2f2a59
10 changed files with 1201 additions and 1033 deletions

View File

@ -142,12 +142,12 @@ func userAddCommandFunc(cmd *cobra.Command, args []string) {
}
}
_, err := mustClientFromCmd(cmd).Auth.UserAdd(context.TODO(), user, password)
resp, err := mustClientFromCmd(cmd).Auth.UserAdd(context.TODO(), user, password)
if err != nil {
ExitWithError(ExitError, err)
}
fmt.Printf("User %s created\n", user)
display.UserAdd(user, *resp)
}
// userDeleteCommandFunc executes the "user delete" command.
@ -156,12 +156,11 @@ func userDeleteCommandFunc(cmd *cobra.Command, args []string) {
ExitWithError(ExitBadArgs, fmt.Errorf("user delete command requires user name as its argument."))
}
_, err := mustClientFromCmd(cmd).Auth.UserDelete(context.TODO(), args[0])
resp, err := mustClientFromCmd(cmd).Auth.UserDelete(context.TODO(), args[0])
if err != nil {
ExitWithError(ExitError, err)
}
fmt.Printf("User %s deleted\n", args[0])
display.UserDelete(args[0], *resp)
}
// userGetCommandFunc executes the "user get" command.
@ -177,23 +176,18 @@ func userGetCommandFunc(cmd *cobra.Command, args []string) {
ExitWithError(ExitError, err)
}
fmt.Printf("User: %s\n", name)
if !userShowDetail {
fmt.Printf("Roles:")
for _, role := range resp.Roles {
fmt.Printf(" %s", role)
}
fmt.Printf("\n")
} else {
if userShowDetail {
fmt.Printf("User: %s\n", name)
for _, role := range resp.Roles {
fmt.Printf("\n")
roleResp, err := client.Auth.RoleGet(context.TODO(), role)
if err != nil {
ExitWithError(ExitError, err)
}
printRolePermissions(role, roleResp)
display.RoleGet(role, *roleResp)
}
} else {
display.UserGet(name, *resp)
}
}
@ -208,9 +202,7 @@ func userListCommandFunc(cmd *cobra.Command, args []string) {
ExitWithError(ExitError, err)
}
for _, user := range resp.Users {
fmt.Printf("%s\n", user)
}
display.UserList(*resp)
}
// userChangePasswordCommandFunc executes the "user passwd" command.
@ -227,12 +219,12 @@ func userChangePasswordCommandFunc(cmd *cobra.Command, args []string) {
password = readPasswordInteractive(args[0])
}
_, err := mustClientFromCmd(cmd).Auth.UserChangePassword(context.TODO(), args[0], password)
resp, err := mustClientFromCmd(cmd).Auth.UserChangePassword(context.TODO(), args[0], password)
if err != nil {
ExitWithError(ExitError, err)
}
fmt.Println("Password updated")
display.UserChangePassword(*resp)
}
// userGrantRoleCommandFunc executes the "user grant-role" command.
@ -241,12 +233,12 @@ func userGrantRoleCommandFunc(cmd *cobra.Command, args []string) {
ExitWithError(ExitBadArgs, fmt.Errorf("user grant command requires user name and role name as its argument."))
}
_, err := mustClientFromCmd(cmd).Auth.UserGrantRole(context.TODO(), args[0], args[1])
resp, err := mustClientFromCmd(cmd).Auth.UserGrantRole(context.TODO(), args[0], args[1])
if err != nil {
ExitWithError(ExitError, err)
}
fmt.Printf("Role %s is granted to user %s\n", args[1], args[0])
display.UserGrantRole(args[0], args[1], *resp)
}
// userRevokeRoleCommandFunc executes the "user revoke-role" command.
@ -255,12 +247,12 @@ func userRevokeRoleCommandFunc(cmd *cobra.Command, args []string) {
ExitWithError(ExitBadArgs, fmt.Errorf("user revoke-role requires user name and role name as its argument."))
}
_, err := mustClientFromCmd(cmd).Auth.UserRevokeRole(context.TODO(), args[0], args[1])
resp, err := mustClientFromCmd(cmd).Auth.UserRevokeRole(context.TODO(), args[0], args[1])
if err != nil {
ExitWithError(ExitError, err)
}
fmt.Printf("Role %s is revoked from user %s\n", args[1], args[0])
display.UserRevokeRole(args[0], args[1], *resp)
}
func readPasswordInteractive(name string) string {