/
whoami.go
51 lines (43 loc) · 1.19 KB
/
whoami.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
package commands
import (
"fmt"
"os"
"strconv"
"github.com/olekukonko/tablewriter"
"github.com/section/sectionctl/api"
)
// WhoAmICmd returns information about the currently authenticated user
type WhoAmICmd struct{}
// PrettyBool pretty prints a bool value
func PrettyBool(b bool) (s string) {
if b {
return "✔"
}
return "✘"
}
// Run executes the command
func (c *WhoAmICmd) Run(cli *CLI, logWriters *LogWriters) (err error) {
s := NewSpinner("Looking up current user",logWriters)
s.Start()
u, err := api.CurrentUser()
s.Stop()
if err != nil {
return err
}
table := NewTable(cli, os.Stdout)
table.SetHeader([]string{"Attribute", "Value"})
r := [][]string{
[]string{"Name", fmt.Sprintf("%s %s", u.FirstName, u.LastName)},
[]string{"Email", u.Email},
[]string{"ID", strconv.Itoa(u.ID)},
[]string{"Company", u.CompanyName},
[]string{"Phone Number", u.PhoneNumber},
[]string{"Verified?", PrettyBool(u.Verified)},
[]string{"Requires 2FA?", PrettyBool(u.Requires2FA)},
}
table.SetColumnColor(tablewriter.Colors{tablewriter.Normal,tablewriter.FgWhiteColor},
tablewriter.Colors{tablewriter.Bold, tablewriter.FgHiGreenColor})
table.AppendBulk(r)
table.Render()
return nil
}