Skip to content
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

DXCDT-600: Show active tenant in auth0 tenants list #910

Merged
merged 9 commits into from
Nov 14, 2023
2 changes: 1 addition & 1 deletion internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func buildRootCmd(cli *cli) *cobra.Command {
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
ansi.Initialize(cli.noColor)
prepareInteractivity(cmd)
cli.configureRenderer()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method mostly serves to attach the active tenant to the renderer struct so that we can make the comparison below. Otherwise, the tenant commands' renderers do not have knowledge of the currently active tenant.


if !commandRequiresAuthentication(cmd.CommandPath()) {
return nil
Expand All @@ -105,7 +106,6 @@ func buildRootCmd(cli *cli) *cobra.Command {
return err
}

cli.configureRenderer()
return nil
},
}
Expand Down
26 changes: 18 additions & 8 deletions internal/display/tenants.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
package display

import "github.com/auth0/auth0-cli/internal/ansi"

type tenantView struct {
Name string
raw interface{}
Active bool
Name string
raw interface{}
}

func (v *tenantView) AsTableHeader() []string {
return []string{"Available tenants"}
return []string{"Active", "Tenant"}
}

func (v *tenantView) AsTableRow() []string {
return []string{v.Name}
activeText := ""
if v.Active {
activeText = ansi.Green("→")
}

return []string{
activeText,
v.Name,
}
}

func (v *tenantView) Object() interface{} {
return v.raw
}

func (r *Renderer) TenantList(data []string) {
r.Heading()

if len(data) == 0 {
r.EmptyState("tenants", "Use 'auth0 login' to add one")
return
Expand All @@ -28,8 +37,9 @@ func (r *Renderer) TenantList(data []string) {
var results []View
for _, item := range data {
results = append(results, &tenantView{
Name: item,
raw: item,
Active: item == r.Tenant,
willvedd marked this conversation as resolved.
Show resolved Hide resolved
Name: item,
raw: item,
})
}

Expand Down
12 changes: 9 additions & 3 deletions test/integration/test-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ config:
retries: 1

tests:
auth0 tenants list:
exit-code: 0

auth0 completion bash:
exit-code: 0

Expand Down Expand Up @@ -100,6 +97,15 @@ tests:
- STAGE_PRE_USER_REGISTRATION_RATE
exit-code: 0

tenants list:
command: auth0 tenants list
exit-code: 0
stdout:
contains:
- ACTIVE
- TENANT
- →

tenants use:
command: auth0 tenants use $AUTH0_DOMAIN
exit-code: 0
Expand Down
Loading