forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename_pipeline.go
57 lines (44 loc) · 1.21 KB
/
rename_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
51
52
53
54
55
56
57
package commands
import (
"fmt"
"github.com/concourse/fly/commands/internal/displayhelpers"
"github.com/concourse/fly/commands/internal/flaghelpers"
"github.com/concourse/fly/rc"
)
type RenamePipelineCommand struct {
Pipeline flaghelpers.PipelineFlag `short:"o" long:"old-name" required:"true" description:"Pipeline to rename"`
Name flaghelpers.PipelineFlag `short:"n" long:"new-name" required:"true" description:"Name to set as pipeline name"`
}
func (command *RenamePipelineCommand) Validate() error {
err := command.Pipeline.Validate()
if err != nil {
return err
}
return command.Name.Validate()
}
func (command *RenamePipelineCommand) Execute([]string) error {
err := command.Validate()
if err != nil {
return err
}
target, err := rc.LoadTarget(Fly.Target, Fly.Verbose)
if err != nil {
return err
}
err = target.Validate()
if err != nil {
return err
}
oldName := string(command.Pipeline)
newName := string(command.Name)
found, err := target.Team().RenamePipeline(oldName, newName)
if err != nil {
return err
}
if !found {
displayhelpers.Failf("pipeline '%s' not found\n", oldName)
return nil
}
fmt.Printf("pipeline successfully renamed to %s\n", newName)
return nil
}