1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-12 08:23:48 +02:00
woodpecker/cli/whoami.go

33 lines
650 B
Go
Raw Normal View History

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)
},
}
}
// 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
}