-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add grpc delete user implementation #190
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,18 +42,8 @@ Note that the user's password must be at least 8 characters long. eg.: | |
var deleteUserCmd = &cobra.Command{ | ||
Use: "user", | ||
Short: "Delete an user", | ||
Long: `Delete an user. | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if userIDFlag == 0 { | ||
Usage(cmd) | ||
return | ||
} | ||
if err := NewTeresa().DeleteUser(userIDFlag); err != nil { | ||
Fatalf(cmd, "Failed to delete user, err: %s\n", err) | ||
} | ||
log.Infof("User deleted.") | ||
}, | ||
Long: `Delete an user.`, | ||
Run: deleteUser, | ||
} | ||
|
||
// set password for an user | ||
|
@@ -84,6 +74,30 @@ func setPassword(cmd *cobra.Command, args []string) { | |
fmt.Println("Password updated") | ||
} | ||
|
||
func deleteUser(cmd *cobra.Command, args []string) { | ||
if userEmailFlag == "" { | ||
Usage(cmd) | ||
return | ||
} | ||
conn, err := connection.New(cfgFile) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "Error connecting to server: ", err) | ||
return | ||
} | ||
defer conn.Close() | ||
|
||
cli := userpb.NewUserClient(conn) | ||
_, err = cli.Delete( | ||
context.Background(), | ||
&userpb.DeleteRequest{Email: userEmailFlag}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of create a new variable for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad, didn't recall our conversation about it. |
||
) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, client.GetErrorMsg(err)) | ||
return | ||
} | ||
fmt.Println("User deleted") | ||
} | ||
|
||
func init() { | ||
createCmd.AddCommand(userCmd) | ||
userCmd.Flags().StringVar(&userNameFlag, "name", "", "user name [required]") | ||
|
@@ -92,7 +106,7 @@ func init() { | |
userCmd.Flags().BoolVar(&isAdminFlag, "admin", false, "admin") | ||
|
||
deleteCmd.AddCommand(deleteUserCmd) | ||
deleteUserCmd.Flags().Int64Var(&userIDFlag, "id", 0, "user ID [required]") | ||
deleteUserCmd.Flags().StringVar(&userEmailFlag, "email", "", "user email [required]") | ||
|
||
RootCmd.AddCommand(setUserPasswordCmd) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
cmd.Usage()
?