woodpecker/cmd/whoami.go

32 lines
604 B
Go
Raw Normal View History

2014-07-16 07:34:23 +00:00
package main
import (
"fmt"
"github.com/codegangsta/cli"
2014-08-09 23:51:08 +00:00
"github.com/drone/drone/client"
2014-07-16 07:34:23 +00:00
)
// 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 executes the "logout" command.
2014-08-09 23:51:08 +00:00
func whoamiCommandFunc(c *cli.Context, client *client.Client) error {
user, err := client.Users.GetCurrent()
2014-07-16 07:34:23 +00:00
if err != nil {
return err
}
fmt.Println(user.Login)
return nil
}