forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline_flag.go
47 lines (36 loc) · 879 Bytes
/
pipeline_flag.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
package flaghelpers
import (
"errors"
"strings"
"github.com/jessevdk/go-flags"
"github.com/concourse/fly/rc"
)
type PipelineFlag string
func (flag *PipelineFlag) Validate() error {
if strings.Contains(string(*flag), "/") {
return errors.New("pipeline name cannot contain '/'")
}
return nil
}
func (flag *PipelineFlag) Complete(match string) []flags.Completion {
fly := parseFlags()
target, err := rc.LoadTarget(fly.Target, false)
if err != nil {
return []flags.Completion{}
}
err = target.Validate()
if err != nil {
return []flags.Completion{}
}
pipelines, err := target.Team().ListPipelines()
if err != nil {
return []flags.Completion{}
}
comps := []flags.Completion{}
for _, pipeline := range pipelines {
if strings.HasPrefix(pipeline.Name, match) {
comps = append(comps, flags.Completion{Item: pipeline.Name})
}
}
return comps
}