/
logins.go
59 lines (49 loc) · 1.11 KB
/
logins.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
package command
import (
"encoding/json"
"fmt"
"os"
"strings"
"text/tabwriter"
. "github.com/ForceCLI/force/config"
. "github.com/ForceCLI/force/lib"
)
var cmdLogins = &Command{
Run: runLogins,
Usage: "logins",
Short: "List force.com logins used",
Long: `
List force.com accounts
Examples:
force logins
`,
}
func runLogins(cmd *Command, args []string) {
active, _ := ActiveLogin()
accounts, _ := Config.List("accounts")
if len(accounts) == 0 {
fmt.Println("no logins")
} else {
w := new(tabwriter.Writer)
w.Init(os.Stdout, 1, 0, 1, ' ', 0)
for _, account := range accounts {
if !strings.HasPrefix(account, ".") {
var creds ForceSession
data, err := Config.Load("accounts", account)
json.Unmarshal([]byte(data), &creds)
if err != nil {
return
}
var banner = fmt.Sprintf("\t%s", creds.InstanceUrl)
if account == active {
account = fmt.Sprintf("\x1b[31;1m%s (active)\x1b[0m", account)
} else {
account = fmt.Sprintf("%s \x1b[31;1m\x1b[0m", account)
}
fmt.Fprintln(w, fmt.Sprintf("%s%s", account, banner))
}
}
fmt.Fprintln(w)
w.Flush()
}
}