MCPcopy Create free account
hub / github.com/auth0/auth0-cli / searchUsersByEmailCmd

Function searchUsersByEmailCmd

internal/cli/users.go:286–353  ·  view source on GitHub ↗
(cli *cli)

Source from the content-addressed store, hash-verified

284}
285
286func searchUsersByEmailCmd(cli *cli) *cobra.Command {
287 var inputs struct {
288 email string
289 picker bool
290 }
291
292 cmd := &cobra.Command{
293 Use: "search-by-email",
294 Args: cobra.MaximumNArgs(1),
295 Short: "Search for users",
296 Long: "Search for users. To create one, run: `auth0 users create`.",
297 Example: ` auth0 users search-by-email
298 auth0 users search-by-email <user-email>,
299 auth0 users search-by-email <user-email> -p`,
300 RunE: func(cmd *cobra.Command, args []string) error {
301 var emailID string
302
303 if len(args) == 0 {
304 if err := userEmail.Ask(cmd, &emailID, nil); err != nil {
305 return err
306 }
307 } else {
308 emailID = args[0]
309 }
310
311 usersList, err := cli.api.User.ListByEmail(cmd.Context(), emailID)
312 if err != nil {
313 return fmt.Errorf("failed to search for users with email - %v: %w", emailID, err)
314 }
315
316 if !inputs.picker || len(usersList) == 0 {
317 cli.renderer.UserSearch(usersList)
318 } else {
319 var (
320 selectedUserID string
321 currentIndex = auth0.Int(0)
322 )
323 for {
324 selectedUserID = cli.renderer.UserPrompt(usersList, currentIndex)
325
326 userDetail, err := cli.api.User.Read(cmd.Context(), selectedUserID)
327 if err != nil {
328 fmt.Println("Failed to fetch details:", err)
329 continue
330 }
331
332 fmt.Println("\nUser Details:")
333 cli.renderer.JSONResult(userDetail)
334
335 if cli.renderer.QuitPrompt() {
336 break
337 }
338 }
339 }
340
341 return nil
342 },
343 }

Callers 1

usersCmdFunction · 0.85

Calls 9

ErrorfMethod · 0.80
UserSearchMethod · 0.80
UserPromptMethod · 0.80
JSONResultMethod · 0.80
QuitPromptMethod · 0.80
RegisterBoolMethod · 0.80
ListByEmailMethod · 0.65
ReadMethod · 0.65
AskMethod · 0.45

Tested by

no test coverage detected