mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-15 22:41:19 +00:00
188b9e6eb5
- move cli files from `cli/drone` to `cli/` - move cli main to `cmd/cli/main.go` to match agent and server - use version from `version/version.go` to match agent and server
63 lines
1.1 KiB
Go
63 lines
1.1 KiB
Go
package build
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"text/template"
|
|
|
|
"github.com/urfave/cli"
|
|
"github.com/woodpecker-ci/woodpecker/cli/internal"
|
|
)
|
|
|
|
var buildQueueCmd = cli.Command{
|
|
Name: "queue",
|
|
Usage: "show build queue",
|
|
ArgsUsage: " ",
|
|
Action: buildQueue,
|
|
Flags: []cli.Flag{
|
|
cli.StringFlag{
|
|
Name: "format",
|
|
Usage: "format output",
|
|
Value: tmplBuildQueue,
|
|
},
|
|
},
|
|
}
|
|
|
|
func buildQueue(c *cli.Context) error {
|
|
|
|
client, err := internal.NewClient(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
builds, err := client.BuildQueue()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(builds) == 0 {
|
|
fmt.Println("there are no pending or running builds")
|
|
return nil
|
|
}
|
|
|
|
tmpl, err := template.New("_").Parse(c.String("format") + "\n")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, build := range builds {
|
|
tmpl.Execute(os.Stdout, build)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// template for build list information
|
|
var tmplBuildQueue = "\x1b[33m{{ .FullName }} #{{ .Number }} \x1b[0m" + `
|
|
Status: {{ .Status }}
|
|
Event: {{ .Event }}
|
|
Commit: {{ .Commit }}
|
|
Branch: {{ .Branch }}
|
|
Ref: {{ .Ref }}
|
|
Author: {{ .Author }} {{ if .Email }}<{{.Email}}>{{ end }}
|
|
Message: {{ .Message }}
|
|
`
|