From fd9fa3842b1d349b2df4521bcb8c9a031bb1186d Mon Sep 17 00:00:00 2001 From: bright-poku Date: Mon, 15 Mar 2021 16:39:29 -0400 Subject: [PATCH] [CLI-62] add alias ls to the list command and display logic --- internal/cli/tenants.go | 19 +++++-------------- internal/display/tenants.go | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 internal/display/tenants.go diff --git a/internal/cli/tenants.go b/internal/cli/tenants.go index bc4c465f4..d9956f872 100644 --- a/internal/cli/tenants.go +++ b/internal/cli/tenants.go @@ -2,9 +2,6 @@ package cli import ( "fmt" - "os" - - "github.com/olekukonko/tablewriter" "github.com/auth0/auth0-cli/internal/prompt" "github.com/spf13/cobra" ) @@ -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 }, } diff --git a/internal/display/tenants.go b/internal/display/tenants.go new file mode 100644 index 000000000..eb7e02966 --- /dev/null +++ b/internal/display/tenants.go @@ -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) +}