mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-22 08:02:36 +00:00
adding stubs for command line API
This commit is contained in:
32
client/command/whoami.go
Normal file
32
client/command/whoami.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/drone/drone/shared/model"
|
||||
)
|
||||
|
||||
// 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.
|
||||
func whoamiCommandFunc(c *cli.Context, client *Client) error {
|
||||
user := model.User{}
|
||||
err := client.Do("GET", "/v1/user", nil, &user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(user.Login)
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user