1
0
mirror of https://github.com/drone/drone-cli.git synced 2024-11-23 01:11:57 +01:00
drone-cli/drone/cron/cron_list.go

60 lines
1.1 KiB
Go
Raw Permalink Normal View History

2018-08-07 01:29:03 +02:00
package cron
import (
"html/template"
"os"
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/funcmap"
"github.com/urfave/cli"
2018-08-07 01:29:03 +02:00
)
var cronListCmd = cli.Command{
Name: "ls",
Usage: "list cron jobs",
ArgsUsage: "[repo/name]",
Action: cronList,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplCronList,
Hidden: true,
},
},
}
func cronList(c *cli.Context) error {
slug := c.Args().First()
owner, name, err := internal.ParseRepo(slug)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
list, err := client.CronList(owner, name)
if err != nil {
return err
}
format := c.String("format") + "\n"
tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(format)
2018-08-07 01:29:03 +02:00
if err != nil {
return err
}
for _, cron := range list {
tmpl.Execute(os.Stdout, cron)
}
return nil
}
// template for build list information
var tmplCronList = "\x1b[33m{{ .Name }} \x1b[0m" + `
Expr: {{ .Expr }}
Next: {{ .Next | time }}
2018-10-22 04:54:57 +02:00
{{- if .Disabled }}
Disabled: true
{{- end }}
2018-08-07 01:29:03 +02:00
`