1
0
mirror of https://github.com/drone/drone-cli.git synced 2024-11-23 17:22:09 +01:00
drone-cli/drone/whoami.go
2015-02-13 00:23:01 -08:00

33 lines
651 B
Go

package main
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/drone/drone-go/drone"
)
// NewWhoamiCommand returns the CLI command for "whoami".
func NewWhoamiCommand() cli.Command {
return cli.Command{
Name: "whoami",
Usage: "outputs the current user",
Flags: []cli.Flag{},
Action: func(c *cli.Context) {
handle(c, whoamiCommandFunc)
},
}
}
// whoamiCommandFunc communicates with the server and echoes
// the currently authenticated user.
func whoamiCommandFunc(c *cli.Context, client *drone.Client) error {
user, err := client.Users.GetCurrent()
if err != nil {
return err
}
fmt.Println(user.Login)
return nil
}