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)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-13 04:53:25 +00:00
|
|
|
// whoamiCommandFunc communicates with the server and echoes
|
|
|
|
// the currently authenticated user.
|
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
|
|
|
|
}
|