forked from jenkins-zh/jenkins-cli
/
queue.go
46 lines (39 loc) · 1000 Bytes
/
queue.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
package cmd
import (
"fmt"
"log"
"github.com/linuxsuren/jenkins-cli/client"
"github.com/spf13/cobra"
)
type QueueOption struct {
OutputOption
}
var queueOption QueueOption
func init() {
rootCmd.AddCommand(queueCmd)
queueCmd.PersistentFlags().StringVarP(&queueOption.Format, "output", "o", "json", "Format the output")
}
var queueCmd = &cobra.Command{
Use: "queue",
Short: "Print the queue of your Jenkins",
Long: `Print the queue of your Jenkins`,
Run: func(cmd *cobra.Command, args []string) {
jenkins := getCurrentJenkins()
jclient := &client.QueueClient{}
jclient.URL = jenkins.URL
jclient.UserName = jenkins.UserName
jclient.Token = jenkins.Token
jclient.Proxy = jenkins.Proxy
jclient.ProxyAuth = jenkins.ProxyAuth
if status, err := jclient.Get(); err == nil {
var data []byte
if data, err = Format(status, queueOption.Format); err == nil {
fmt.Printf("%s\n", string(data))
} else {
log.Fatal(err)
}
} else {
log.Fatal(err)
}
},
}