2014-07-16 10:34:23 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
2014-08-10 02:51:08 +03:00
|
|
|
"github.com/drone/drone/client"
|
2014-07-16 10:34:23 +03: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 07:53:25 +03:00
|
|
|
// whoamiCommandFunc communicates with the server and echoes
|
|
|
|
// the currently authenticated user.
|
2014-08-10 02:51:08 +03:00
|
|
|
func whoamiCommandFunc(c *cli.Context, client *client.Client) error {
|
|
|
|
user, err := client.Users.GetCurrent()
|
2014-07-16 10:34:23 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(user.Login)
|
|
|
|
return nil
|
|
|
|
}
|