Skip to content

Commit

Permalink
Merge branch 'main' into test-token-retriever
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket authored Mar 15, 2021
2 parents b7189b7 + 87d664b commit bb8b7f0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
27 changes: 26 additions & 1 deletion internal/cli/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"fmt"

"github.com/auth0/auth0-cli/internal/prompt"
"github.com/spf13/cobra"
)
Expand All @@ -14,9 +13,35 @@ func tenantsCmd(cli *cli) *cobra.Command {
}

cmd.AddCommand(useTenantCmd(cli))
cmd.AddCommand(listTenantCmd(cli))
return cmd
}

func listTenantCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List your tenants",
Long: `auth0 tenants list`,
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
tens, err := cli.listTenants()
if err != nil {
return fmt.Errorf("Unable to load tenants due to an unexpected error: %w", err)
}

tenNames := make([]string, len(tens))
for i, t := range tens {
tenNames[i] = t.Name
}

cli.renderer.ShowTenants(tenNames)
return nil
},
}
return cmd
}


func useTenantCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "use",
Expand Down
24 changes: 24 additions & 0 deletions internal/display/tenants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package display

type tenantView struct {
Name string
}

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

func (v *tenantView) AsTableRow() []string {
return []string{v.Name}
}

func (r *Renderer) ShowTenants(data []string) {
var results []View
for _, item := range data {
results = append(results, &tenantView{
Name: item,
})
}

r.Results(results)
}

0 comments on commit bb8b7f0

Please sign in to comment.