Skip to content

Commit

Permalink
[cli] Better flags handling for the delete user cmd
Browse files Browse the repository at this point in the history
Avoid globals and use cmd.Usage().
  • Loading branch information
Alex Guerra authored and drgarcia1986 committed May 18, 2017
1 parent 861b94c commit 142bce3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cmd/client/cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ func setPassword(cmd *cobra.Command, args []string) {
}

func deleteUser(cmd *cobra.Command, args []string) {
if userEmailFlag == "" {
Usage(cmd)
email, _ := cmd.Flags().GetString("email")
if email == "" {
cmd.Usage()
return
}
conn, err := connection.New(cfgFile)
Expand All @@ -89,7 +90,7 @@ func deleteUser(cmd *cobra.Command, args []string) {
cli := userpb.NewUserClient(conn)
_, err = cli.Delete(
context.Background(),
&userpb.DeleteRequest{Email: userEmailFlag},
&userpb.DeleteRequest{Email: email},
)
if err != nil {
fmt.Fprintln(os.Stderr, client.GetErrorMsg(err))
Expand All @@ -106,7 +107,7 @@ func init() {
userCmd.Flags().BoolVar(&isAdminFlag, "admin", false, "admin")

deleteCmd.AddCommand(deleteUserCmd)
deleteUserCmd.Flags().StringVar(&userEmailFlag, "email", "", "user email [required]")
deleteUserCmd.Flags().String("email", "", "user email [required]")

RootCmd.AddCommand(setUserPasswordCmd)
}

0 comments on commit 142bce3

Please sign in to comment.