forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
destroy_pipeline.go
50 lines (40 loc) · 1.1 KB
/
destroy_pipeline.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
package commands
import (
"fmt"
"github.com/concourse/fly/rc"
"github.com/vito/go-interact/interact"
)
type DestroyPipelineCommand struct {
Pipeline string `short:"p" long:"pipeline" required:"true" description:"Pipeline to destroy"`
SkipInteractive bool `short:"n" long:"non-interactive" description:"Destroy the pipeline without confirmation"`
}
func (command *DestroyPipelineCommand) Execute(args []string) error {
target, err := rc.LoadTarget(Fly.Target)
if err != nil {
return err
}
err = target.Validate()
if err != nil {
return err
}
pipelineName := command.Pipeline
fmt.Printf("!!! this will remove all data for pipeline `%s`\n\n", pipelineName)
confirm := command.SkipInteractive
if !confirm {
err := interact.NewInteraction("are you sure?").Resolve(&confirm)
if err != nil || !confirm {
fmt.Println("bailing out")
return err
}
}
found, err := target.Team().DeletePipeline(pipelineName)
if err != nil {
return err
}
if !found {
fmt.Printf("`%s` does not exist\n", pipelineName)
} else {
fmt.Printf("`%s` deleted\n", pipelineName)
}
return nil
}