github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/fly/commands/rename_pipeline.go (about) 1 package commands 2 3 import ( 4 "errors" 5 "fmt" 6 "strings" 7 8 "github.com/pf-qiu/concourse/v6/fly/commands/internal/displayhelpers" 9 "github.com/pf-qiu/concourse/v6/fly/commands/internal/flaghelpers" 10 "github.com/pf-qiu/concourse/v6/fly/rc" 11 ) 12 13 type RenamePipelineCommand struct { 14 Pipeline flaghelpers.PipelineFlag `short:"o" long:"old-name" required:"true" description:"Pipeline to rename"` 15 NewName string `short:"n" long:"new-name" required:"true" description:"Name to set as pipeline name"` 16 } 17 18 func (command *RenamePipelineCommand) Validate() error { 19 _, err := command.Pipeline.Validate() 20 if err != nil { 21 return err 22 } 23 24 if strings.Contains(command.NewName, "/") { 25 return errors.New("pipeline name cannot contain '/'") 26 } 27 return nil 28 } 29 30 func (command *RenamePipelineCommand) Execute([]string) error { 31 err := command.Validate() 32 if err != nil { 33 return err 34 } 35 36 target, err := rc.LoadTarget(Fly.Target, Fly.Verbose) 37 if err != nil { 38 return err 39 } 40 41 err = target.Validate() 42 if err != nil { 43 return err 44 } 45 46 pipelineRef := command.Pipeline.Ref() 47 newName := command.NewName 48 49 found, warnings, err := target.Team().RenamePipeline(pipelineRef, newName) 50 if err != nil { 51 return err 52 } 53 54 if len(warnings) > 0 { 55 displayhelpers.ShowWarnings(warnings) 56 } 57 58 if !found { 59 displayhelpers.Failf("pipeline '%s' not found\n", pipelineRef.String()) 60 return nil 61 } 62 63 fmt.Printf("pipeline successfully renamed to %s\n", newName) 64 65 return nil 66 }