-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathlogout.go
More file actions
46 lines (41 loc) · 1.02 KB
/
Copy pathlogout.go
File metadata and controls
46 lines (41 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package command
import (
"fmt"
"os/exec"
"runtime"
. "github.com/ForceCLI/force/config"
. "github.com/ForceCLI/force/error"
. "github.com/ForceCLI/force/lib"
"github.com/spf13/cobra"
)
func init() {
RootCmd.AddCommand(logoutCmd)
}
var logoutCmd = &cobra.Command{
Use: "logout",
Short: "Log out from Force.com",
Args: cobra.MaximumNArgs(0),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
runLogout()
},
}
func runLogout() {
accounts, _ := Config.List("accounts")
if len(accounts) == 0 {
ErrorAndExit("No logins, so a username cannot be assumed.")
}
username := force.Credentials.UserInfo.UserName
Config.Delete("accounts", username)
if active, _ := Config.Load("current", "account"); active == username {
Config.Delete("current", "account")
SetActiveLoginDefault()
}
if runtime.GOOS == "windows" {
cmd := exec.Command("title", username)
cmd.Run()
} else {
title := fmt.Sprintf("\033];%s\007", "")
fmt.Printf(title)
}
}