diff --git a/internal/cli/tenants.go b/internal/cli/tenants.go index 03476e381..d9956f872 100644 --- a/internal/cli/tenants.go +++ b/internal/cli/tenants.go @@ -2,7 +2,6 @@ package cli import ( "fmt" - "github.com/auth0/auth0-cli/internal/prompt" "github.com/spf13/cobra" ) @@ -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", diff --git a/internal/display/tenants.go b/internal/display/tenants.go new file mode 100644 index 000000000..fcc968752 --- /dev/null +++ b/internal/display/tenants.go @@ -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) +}