1
0
Fork 0
mirror of https://github.com/drone/drone-cli.git synced 2024-05-26 08:46:03 +02:00
drone-cli/drone/agent.go
2016-05-25 09:43:33 -07:00

60 lines
1.0 KiB
Go

package main
import (
"html/template"
"os"
"time"
"github.com/codegangsta/cli"
)
var agentCmd = cli.Command{
Name: "agents",
Usage: "manage agents",
Action: agentList,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplAgentList,
},
},
}
func agentList(c *cli.Context) error {
client, err := newClient(c)
if err != nil {
return err
}
agents, err := client.AgentList()
if err != nil {
return err
}
tmpl, err := template.New("_").Funcs(funcMap).Parse(c.String("format") + "\n")
if err != nil {
return err
}
for _, agent := range agents {
tmpl.Execute(os.Stdout, agent)
}
return nil
}
// template for build list information
var tmplAgentList = "\x1b[33m{{ .Address }} \x1b[0m" + `
Platform: {{ .Platform }}
Capacity: {{ .Capacity }} concurrent build(s)
Pinged: {{ since .Updated }} ago
Uptime: {{ since .Created }}
`
var funcMap = template.FuncMap{
"since": func(t int64) string {
d := time.Now().Sub(time.Unix(t, 0))
return d.String()
},
}