Skip to content

Commit

Permalink
Add user role list renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Jan 12, 2023
1 parent 4a2fd42 commit 3094faf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/cli/users_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func showUserRolesCmd(cli *cli) *cobra.Command {
return fmt.Errorf("failed to find roles for user with ID %s: %w", inputs.ID, err)
}

cli.renderer.RoleList(userRoleList.Roles)
cli.renderer.UserRoleList(userRoleList.Roles)

return nil
},
Expand Down
18 changes: 18 additions & 0 deletions internal/display/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ func (r *Renderer) RoleList(roles []*management.Role) {
r.Results(res)
}

func (r *Renderer) UserRoleList(roles []*management.Role) {
resource := "roles assigned to user"
r.Heading(fmt.Sprintf("%s (%d)", resource, len(roles)))

if len(roles) == 0 {
r.EmptyState(resource)
r.Infof("Use 'auth0 users roles assign' to add one")
return
}

var res []View
for _, role := range roles {
res = append(res, makeRoleView(role))
}

r.Results(res)
}

func (r *Renderer) RoleShow(role *management.Role) {
r.Heading("role")
r.Result(makeRoleView(role))
Expand Down

0 comments on commit 3094faf

Please sign in to comment.