This repository has been archived by the owner on Jul 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_pipelines.go
102 lines (75 loc) · 2.04 KB
/
cmd_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"github.com/exograd/go-program"
)
func addPipelineCommands() {
var c *program.Command
// list-pipelines
c = p.AddCommand("list-pipelines", "list pipelines",
cmdListPipelines)
// abort-pipeline
c = p.AddCommand("abort-pipeline", "abort a pipeline",
cmdAbortPipeline)
c.AddArgument("pipeline-id", "the pipeline to abort")
// restart-pipeline
c = p.AddCommand("restart-pipeline", "restart a pipeline",
cmdRestartPipeline)
c.AddArgument("pipeline-id", "the pipeline to restart")
// restart-pipeline-from-failure
c = p.AddCommand("restart-pipeline-from-failure",
"restart a pipeline from failed or aborted tasks",
cmdRestartPipelineFromFailure)
c.AddArgument("pipeline-id", "the pipeline to restart")
}
func cmdListPipelines(p *program.Program) {
app.IdentifyCurrentProject()
pipelines, err := app.Client.FetchPipelines()
if err != nil {
p.Fatal("cannot fetch pipelines: %v", err)
}
header := []string{
"id",
"name",
"event time",
"start time",
"duration",
"status",
}
table := NewTable(header)
for _, pipeline := range pipelines {
row := []interface{}{
pipeline.Id,
pipeline.Name,
pipeline.EventTime,
pipeline.StartTime,
pipeline.Duration(),
pipeline.Status,
}
table.AddRow(row)
}
table.Write()
}
func cmdAbortPipeline(p *program.Program) {
app.IdentifyCurrentProject()
Id := p.ArgumentValue("pipeline-id")
if err := app.Client.AbortPipeline(Id); err != nil {
p.Fatal("cannot abort pipeline: %v", err)
}
p.Info("pipeline aborted")
}
func cmdRestartPipeline(p *program.Program) {
app.IdentifyCurrentProject()
Id := p.ArgumentValue("pipeline-id")
if err := app.Client.RestartPipeline(Id); err != nil {
p.Fatal("cannot restart pipeline: %v", err)
}
p.Info("pipeline restarted")
}
func cmdRestartPipelineFromFailure(p *program.Program) {
app.IdentifyCurrentProject()
Id := p.ArgumentValue("pipeline-id")
if err := app.Client.RestartPipelineFromFailure(Id); err != nil {
p.Fatal("cannot restart pipeline from failure: %v", err)
}
p.Info("pipeline restarted")
}