From c9317b6ef2765f0dddf89bf439a734f9312daf68 Mon Sep 17 00:00:00 2001 From: "Jorge L. Fatta" Date: Tue, 30 Mar 2021 09:22:43 -0300 Subject: [PATCH] fix: logout --- internal/cli/logout.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/cli/logout.go b/internal/cli/logout.go index 4e6883105..6f736fd26 100644 --- a/internal/cli/logout.go +++ b/internal/cli/logout.go @@ -1,6 +1,7 @@ package cli import ( + "errors" "fmt" "github.com/auth0/auth0-cli/internal/prompt" @@ -12,7 +13,7 @@ func logoutCmd(cli *cli) *cobra.Command { Use: "logout", Short: "Logout of a tenant's session", Long: `auth0 logout `, - Args: cobra.MaximumNArgs(1), + Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { // NOTE(cyx): This was mostly copy/pasted from tenants // use command. Consider refactoring. @@ -23,12 +24,16 @@ func logoutCmd(cli *cli) *cobra.Command { return fmt.Errorf("Unable to load tenants due to an unexpected error: %w", err) } + if len(tens) == 0 { + return errors.New("there are no tenants available to perform the logout") + } + tenNames := make([]string, len(tens)) for i, t := range tens { tenNames[i] = t.Name } - input := prompt.SelectInput("tenant", "Tenant:", "Tenant to activate", tenNames, "", true) + input := prompt.SelectInput("tenant", "Tenant:", "Tenant to logout", tenNames, tenNames[0], true) if err := prompt.AskOne(input, &selectedTenant); err != nil { return fmt.Errorf("An unexpected error occurred: %w", err) }