Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
switch account won't clear the token anymore if a nonexistent account…
Browse files Browse the repository at this point in the history
… is supplied
  • Loading branch information
Bios-Marcel committed Oct 13, 2019
1 parent 191be85 commit c856f74
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions commands/commandimpls/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commandimpls

import (
"fmt"
"github.com/Bios-Marcel/cordless/commands"
"io"
"strings"

Expand Down Expand Up @@ -145,21 +146,20 @@ func (account *Account) printAccountSwitchHelp(writer io.Writer) {
}

func (account *Account) switchAccount(writer io.Writer, accountName string) {
var newToken string
for _, acc := range config.GetConfig().Accounts {
if acc.Name == accountName {
newToken = acc.Token
break
oldToken := config.GetConfig().Token
config.GetConfig().Token = acc.Token
persistError := account.saveAndRestart(writer)
if persistError != nil {
config.GetConfig().Token = oldToken
commands.PrintError(writer, "Error switching accounts", persistError.Error())
}
return
}
}

oldToken := config.GetConfig().Token
config.GetConfig().Token = newToken
persistError := account.saveAndRestart(writer)
if persistError != nil {
config.GetConfig().Token = oldToken
fmt.Fprintf(writer, "["+tviewutil.ColorToHex(config.GetTheme().ErrorColor)+"]Error switching accounts '%s'.\n", persistError.Error())
}
commands.PrintError(writer, "Error switching accounts", fmt.Sprintf("No account named '%s' was found", accountName))
}

func (account *Account) logout(writer io.Writer) {
Expand Down

0 comments on commit c856f74

Please sign in to comment.