forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipelines.go
75 lines (62 loc) · 1.59 KB
/
pipelines.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package commands
import (
"os"
"github.com/concourse/atc"
"github.com/concourse/fly/rc"
"github.com/concourse/fly/ui"
"github.com/fatih/color"
)
type PipelinesCommand struct {
All bool `short:"a" long:"all" description:"Show all pipelines"`
}
func (command *PipelinesCommand) Execute([]string) error {
target, err := rc.LoadTarget(Fly.Target)
if err != nil {
return err
}
err = target.Validate()
if err != nil {
return err
}
var headers []string
var pipelines []atc.Pipeline
if command.All {
pipelines, err = target.Client().ListPipelines()
headers = []string{"name", "team", "paused", "public"}
} else {
pipelines, err = target.Team().ListPipelines()
headers = []string{"name", "paused", "public"}
}
if err != nil {
return err
}
table := ui.Table{Headers: ui.TableRow{}}
for _, h := range headers {
table.Headers = append(table.Headers, ui.TableCell{Contents: h, Color: color.New(color.Bold)})
}
for _, p := range pipelines {
var pausedColumn ui.TableCell
if p.Paused {
pausedColumn.Contents = "yes"
pausedColumn.Color = color.New(color.FgCyan)
} else {
pausedColumn.Contents = "no"
}
var publicColumn ui.TableCell
if p.Public {
publicColumn.Contents = "yes"
publicColumn.Color = color.New(color.FgCyan)
} else {
publicColumn.Contents = "no"
}
row := ui.TableRow{}
row = append(row, ui.TableCell{Contents: p.Name})
if command.All {
row = append(row, ui.TableCell{Contents: p.TeamName})
}
row = append(row, pausedColumn)
row = append(row, publicColumn)
table.Data = append(table.Data, row)
}
return table.Render(os.Stdout)
}