Skip to content

Commit

Permalink
[CLI-62] add alias ls to the list command and display logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bright-poku committed Mar 15, 2021
1 parent 73724b2 commit fd9fa38
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
19 changes: 5 additions & 14 deletions internal/cli/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package cli

import (
"fmt"
"os"

"github.com/olekukonko/tablewriter"
"github.com/auth0/auth0-cli/internal/prompt"
"github.com/spf13/cobra"
)
Expand All @@ -25,25 +22,19 @@ func listTenantCmd(cli *cli) *cobra.Command {
Use: "list",
Short: "List your tenants",
Long: `auth0 tenants list`,
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
listTenant, err := cli.listTenants()
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(listTenant))
for i, t := range listTenant {
tenNames := make([]string, len(tens))
for i, t := range tens {
tenNames[i] = t.Name
}

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

table.Render()
cli.renderer.ShowTenants(tenNames)
return nil
},
}
Expand Down
26 changes: 26 additions & 0 deletions internal/display/tenants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package display

//import "gopkg.in/auth0.v5"

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 fd9fa38

Please sign in to comment.