forked from digitalocean/doctl
/
account.go
40 lines (33 loc) · 864 Bytes
/
account.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
package main
import (
"log"
"github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/digitalocean/doctl/Godeps/_workspace/src/github.com/digitalocean/godo"
"github.com/digitalocean/doctl/Godeps/_workspace/src/golang.org/x/oauth2"
)
var AccountCommand = cli.Command{
Name: "account",
Aliases: []string{"whoami"},
Usage: "Account commands.",
Action: accountShow,
Subcommands: []cli.Command{
{
Name: "show",
Aliases: []string{"s"},
Usage: "Show an account.",
Action: accountShow,
},
},
}
func accountShow(ctx *cli.Context) {
tokenSource := &TokenSource{
AccessToken: APIKey,
}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
account, _, err := client.Account.Get()
if err != nil {
log.Fatal(err)
}
WriteOutput(account)
}