2017-04-29 17:03:45 +00:00
|
|
|
package info
|
2016-05-06 17:59:36 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"text/template"
|
|
|
|
|
2017-03-16 10:14:02 +00:00
|
|
|
"github.com/urfave/cli"
|
2017-04-29 17:03:45 +00:00
|
|
|
|
|
|
|
"github.com/drone/drone/drone/internal"
|
2016-05-06 17:59:36 +00:00
|
|
|
)
|
|
|
|
|
2017-04-29 17:03:45 +00:00
|
|
|
// Command exports the info command.
|
|
|
|
var Command = cli.Command{
|
2017-03-16 10:14:02 +00:00
|
|
|
Name: "info",
|
|
|
|
Usage: "show information about the current user",
|
|
|
|
Action: info,
|
2016-05-06 17:59:36 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
2017-04-29 17:03:45 +00:00
|
|
|
Name: "format",
|
|
|
|
Usage: "format output",
|
|
|
|
Value: tmplInfo,
|
|
|
|
Hidden: true,
|
2016-05-06 17:59:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func info(c *cli.Context) error {
|
2017-04-29 17:03:45 +00:00
|
|
|
client, err := internal.NewClient(c)
|
2016-05-06 17:59:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := client.Self()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpl, err := template.New("_").Parse(c.String("format") + "\n")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return tmpl.Execute(os.Stdout, user)
|
|
|
|
}
|
|
|
|
|
|
|
|
// template for user information
|
|
|
|
var tmplInfo = `User: {{ .Login }}
|
|
|
|
Email: {{ .Email }}`
|