1
0
mirror of https://github.com/drone/drone-cli.git synced 2026-01-17 00:21:32 +01:00
drone-cli/drone/node/node_list.go

50 lines
849 B
Go
Raw Normal View History

2018-11-26 22:32:34 +01:00
package node
import (
"html/template"
"os"
"github.com/urfave/cli"
"github.com/drone/drone-cli/drone/internal"
)
var nodeListCmd = cli.Command{
Name: "ls",
Usage: "list nodes",
Action: nodeList,
Flags: []cli.Flag{
cli.StringFlag{
2019-07-18 23:43:42 +02:00
Name: "format",
Usage: "format output",
Value: tmplNodeList,
2018-11-26 22:32:34 +01:00
},
},
}
func nodeList(c *cli.Context) error {
client, err := internal.NewClient(c)
if err != nil {
return err
}
list, err := client.NodeList()
if err != nil {
return err
}
format := c.String("format") + "\n"
tmpl, err := template.New("_").Parse(format)
if err != nil {
return err
}
for _, cron := range list {
tmpl.Execute(os.Stdout, cron)
}
return nil
}
// template for node list information
var tmplNodeList = "\x1b[33m{{ .Name }} \x1b[0m" + `
Address: {{ .Address }}
Platform: {{ .OS }}/{{ .Arch }}
`