(cli *cli)
| 61 | } |
| 62 | |
| 63 | func showUserRolesCmd(cli *cli) *cobra.Command { |
| 64 | var inputs userRolesInput |
| 65 | |
| 66 | cmd := &cobra.Command{ |
| 67 | Use: "show", |
| 68 | Args: cobra.MaximumNArgs(1), |
| 69 | Short: "Show a user's roles", |
| 70 | Long: "Display information about an existing user's assigned roles.", |
| 71 | Example: ` auth0 users roles show |
| 72 | auth0 users roles show <user-id> |
| 73 | auth0 users roles show <user-id> --number 100 |
| 74 | auth0 users roles show <user-id> -n 100 --json |
| 75 | auth0 users roles show <user-id> -n 100 --json-compact |
| 76 | auth0 users roles show <user-id> --csv`, |
| 77 | RunE: func(cmd *cobra.Command, args []string) error { |
| 78 | if len(args) == 0 { |
| 79 | if err := userID.Ask(cmd, &inputs.ID); err != nil { |
| 80 | return err |
| 81 | } |
| 82 | } else { |
| 83 | inputs.ID = args[0] |
| 84 | } |
| 85 | |
| 86 | if inputs.Number < 1 || inputs.Number > 1000 { |
| 87 | return fmt.Errorf("number flag invalid, please pass a number between 1 and 1000") |
| 88 | } |
| 89 | |
| 90 | list, err := getWithPagination( |
| 91 | inputs.Number, |
| 92 | func(opts ...management.RequestOption) (result []interface{}, hasNext bool, err error) { |
| 93 | userRoleList, err := cli.api.User.Roles(cmd.Context(), inputs.ID, opts...) |
| 94 | if err != nil { |
| 95 | return nil, false, err |
| 96 | } |
| 97 | |
| 98 | var output []interface{} |
| 99 | for _, userRole := range userRoleList.Roles { |
| 100 | output = append(output, userRole) |
| 101 | } |
| 102 | |
| 103 | return output, userRoleList.HasNext(), nil |
| 104 | }, |
| 105 | ) |
| 106 | if err != nil { |
| 107 | return fmt.Errorf("failed to read roles for user with ID %q: %w", inputs.ID, err) |
| 108 | } |
| 109 | |
| 110 | var userRoles []*management.Role |
| 111 | for _, item := range list { |
| 112 | userRoles = append(userRoles, item.(*management.Role)) |
| 113 | } |
| 114 | |
| 115 | cli.renderer.UserRoleList(userRoles) |
| 116 | |
| 117 | return nil |
| 118 | }, |
| 119 | } |
| 120 |
no test coverage detected