forked from harness/drone-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
48 lines (39 loc) · 809 Bytes
/
info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package info
import (
"os"
"text/template"
"github.com/urfave/cli"
"github.com/drone/drone-cli/drone/internal"
)
// Command exports the info command.
var Command = cli.Command{
Name: "info",
Usage: "show information about the current user",
ArgsUsage: " ",
Action: info,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplInfo,
},
},
}
func info(c *cli.Context) error {
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 }}`