github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/fly/commands/expose_pipeline.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 6 "github.com/pf-qiu/concourse/v6/fly/commands/internal/displayhelpers" 7 "github.com/pf-qiu/concourse/v6/fly/commands/internal/flaghelpers" 8 "github.com/pf-qiu/concourse/v6/fly/rc" 9 "github.com/pf-qiu/concourse/v6/go-concourse/concourse" 10 ) 11 12 type ExposePipelineCommand struct { 13 Pipeline flaghelpers.PipelineFlag `short:"p" long:"pipeline" required:"true" description:"Pipeline to expose"` 14 Team string `long:"team" description:"Name of the team to which the pipeline belongs, if different from the target default"` 15 } 16 17 func (command *ExposePipelineCommand) Validate() error { 18 _, err := command.Pipeline.Validate() 19 return err 20 } 21 22 func (command *ExposePipelineCommand) Execute(args []string) error { 23 err := command.Validate() 24 if err != nil { 25 return err 26 } 27 28 target, err := rc.LoadTarget(Fly.Target, Fly.Verbose) 29 if err != nil { 30 return err 31 } 32 33 err = target.Validate() 34 if err != nil { 35 return err 36 } 37 38 var team concourse.Team 39 40 if command.Team != "" { 41 team, err = target.FindTeam(command.Team) 42 if err != nil { 43 return err 44 } 45 } else { 46 team = target.Team() 47 } 48 49 pipelineRef := command.Pipeline.Ref() 50 found, err := team.ExposePipeline(pipelineRef) 51 if err != nil { 52 return err 53 } 54 55 if found { 56 fmt.Printf("exposed '%s'\n", pipelineRef.String()) 57 } else { 58 displayhelpers.Failf("pipeline '%s' not found\n", pipelineRef.String()) 59 } 60 61 return nil 62 }