Skip to content

Commit

Permalink
[CLI-62] cli command to list tenants available
Browse files Browse the repository at this point in the history
  • Loading branch information
bright-poku committed Mar 15, 2021
1 parent 732b4b6 commit a276969
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions internal/cli/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cli

import (
"fmt"
"github.com/olekukonko/tablewriter"
"os"

"github.com/auth0/auth0-cli/internal/prompt"
"github.com/spf13/cobra"
Expand All @@ -14,9 +16,41 @@ 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`,
RunE: func(cmd *cobra.Command, args []string) error {
listTenant, err := cli.listTenants()
if err != nil {
return fmt.Errorf("Unable to load tenants due to an unexpected error: %w", err)
}

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

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Available tenants"})
for _, val := range tenNames {
b := []string{val}
table.Append(b)
}

table.Render()
return nil
},
}
return cmd
}


func useTenantCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "use",
Expand Down

0 comments on commit a276969

Please sign in to comment.