Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logout #212

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions internal/cli/logout.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"errors"
"fmt"

"github.com/auth0/auth0-cli/internal/prompt"
Expand All @@ -12,7 +13,7 @@ func logoutCmd(cli *cli) *cobra.Command {
Use: "logout",
Short: "Logout of a tenant's session",
Long: `auth0 logout <tenant>`,
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.
Expand All @@ -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)
}
Expand Down