github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/fly/commands/internal/flaghelpers/team_flag.go (about)

     1  package flaghelpers
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/pf-qiu/concourse/v6/fly/rc"
     7  	"github.com/jessevdk/go-flags"
     8  )
     9  
    10  type TeamFlag string
    11  
    12  func (flag *TeamFlag) Complete(match string) []flags.Completion {
    13  	fly := parseFlags()
    14  
    15  	target, err := rc.LoadTarget(fly.Target, false)
    16  	if err != nil {
    17  		return []flags.Completion{}
    18  	}
    19  
    20  	teams, err := target.Client().ListTeams()
    21  	if err != nil {
    22  		return []flags.Completion{}
    23  	}
    24  
    25  	comps := []flags.Completion{}
    26  	for _, team := range teams {
    27  		if strings.HasPrefix(team.Name, match) {
    28  			comps = append(comps, flags.Completion{Item: team.Name})
    29  		}
    30  	}
    31  
    32  	return comps
    33  }
    34  
    35  func (flag TeamFlag) Name() string {
    36  	return string(flag)
    37  }