harness-drone/drone/info/info.go

49 lines
799 B
Go
Raw Normal View History

2017-04-29 17:03:45 +00:00
package info
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"
)
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,
Flags: []cli.Flag{
cli.StringFlag{
2017-04-29 17:03:45 +00:00
Name: "format",
Usage: "format output",
Value: tmplInfo,
Hidden: true,
},
},
}
func info(c *cli.Context) error {
2017-04-29 17:03:45 +00:00
client, err := internal.NewClient(c)
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 }}`