Skip to content

Commit

Permalink
Merge pull request #162 from auth0/CLI-62
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket authored Mar 15, 2021
2 parents 7d87ddb + 2ba0f42 commit 87d664b
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 87d664b

Please sign in to comment.