Skip to content

Commit

Permalink
Merge pull request #449 from MrDOS/easy-logout
Browse files Browse the repository at this point in the history
Easy logout when only one username is logged in
  • Loading branch information
dcarroll authored Oct 4, 2017
2 parents bf0168b + ae865f5 commit 31f5221
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions command/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ import (
"runtime"

. "github.com/heroku/force/config"
. "github.com/heroku/force/error"
. "github.com/heroku/force/lib"
)

var cmdLogout = &Command{
Usage: "logout",
Short: "Log out from force.com",
Usage: "logout [-u=username]",
Short: "Log out from Force.com",
Long: `
force logout -u=username
Log out from Force.com
Example:
The username may be omitted when only one account is logged in, in which case
that single logged-in account will be logged out.
force logout -u=user@example.org
Examples:
force logout
force logout -u=user@example.org
`,
}

Expand All @@ -26,17 +30,24 @@ func init() {
}

var (
userName1 = cmdLogout.Flag.String("u", "", "Username for Soap Login")
logoutUserName = cmdLogout.Flag.String("u", "", "Username to log out")
)

func runLogout(cmd *Command, args []string) {
if *userName1 == "" {
fmt.Println("Missing required argument...")
cmd.Flag.Usage()
return
/* If a username was specified, we will use it regardless of logins.
* Otherwise, if there's only one login, we'll use that. */
if *logoutUserName == "" {
accounts, _ := Config.List("accounts")
if len(accounts) == 0 {
ErrorAndExit("No logins, so a username cannot be assumed.")
} else if len(accounts) > 1 {
ErrorAndExit("More than one login. Please specify a username.")
} else {
logoutUserName = &accounts[0]
}
}
Config.Delete("accounts", *userName1)
if active, _ := Config.Load("current", "account"); active == *userName1 {
Config.Delete("accounts", *logoutUserName)
if active, _ := Config.Load("current", "account"); active == *logoutUserName {
Config.Delete("current", "account")
SetActiveLoginDefault()
}
Expand Down

0 comments on commit 31f5221

Please sign in to comment.