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

Function showUserRolesCmd

internal/cli/users_roles.go:63–129  ·  view source on GitHub ↗
(cli *cli)

Source from the content-addressed store, hash-verified

61}
62
63func 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

Callers 1

userRolesCmdFunction · 0.85

Calls 6

getWithPaginationFunction · 0.85
ErrorfMethod · 0.80
UserRoleListMethod · 0.80
RegisterIntMethod · 0.80
RolesMethod · 0.65
AskMethod · 0.45

Tested by

no test coverage detected