Skip to content

Commit

Permalink
DXCDT-600: Show active tenant in auth0 tenants list (#910)
Browse files Browse the repository at this point in the history
* Adding active column to auth0 tenants list

* Fixing test case

* Removing red X for inactive tenant

* Changing checkmark to arrwo

---------

Co-authored-by: Will Vedder <[email protected]>
  • Loading branch information
willvedd and willvedd authored Nov 14, 2023
1 parent 0910c2a commit 2314fe8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
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()

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,
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

0 comments on commit 2314fe8

Please sign in to comment.