github.com/chenbh/concourse/v6@v6.4.2/fly/commands/internal/flaghelpers/pipeline_flag.go (about) 1 package flaghelpers 2 3 import ( 4 "errors" 5 "strings" 6 7 "github.com/jessevdk/go-flags" 8 9 "github.com/chenbh/concourse/v6/atc" 10 "github.com/chenbh/concourse/v6/fly/rc" 11 "github.com/chenbh/concourse/v6/go-concourse/concourse" 12 ) 13 14 type PipelineFlag string 15 16 func (flag *PipelineFlag) Validate() ([]concourse.ConfigWarning, error) { 17 if strings.Contains(string(*flag), "/") { 18 return nil, errors.New("pipeline name cannot contain '/'") 19 } 20 21 var warnings []concourse.ConfigWarning 22 if warning := atc.ValidateIdentifier(string(*flag), "pipeline"); warning != nil { 23 warnings = append(warnings, concourse.ConfigWarning{ 24 Type: warning.Type, 25 Message: warning.Message, 26 }) 27 } 28 return warnings, nil 29 } 30 31 func (flag *PipelineFlag) Complete(match string) []flags.Completion { 32 fly := parseFlags() 33 34 target, err := rc.LoadTarget(fly.Target, false) 35 if err != nil { 36 return []flags.Completion{} 37 } 38 39 err = target.Validate() 40 if err != nil { 41 return []flags.Completion{} 42 } 43 44 pipelines, err := target.Team().ListPipelines() 45 if err != nil { 46 return []flags.Completion{} 47 } 48 49 comps := []flags.Completion{} 50 for _, pipeline := range pipelines { 51 if strings.HasPrefix(pipeline.Name, match) { 52 comps = append(comps, flags.Completion{Item: pipeline.Name}) 53 } 54 } 55 56 return comps 57 }