github.com/beauknowssoftware/makehcl@v0.0.0-20200322000747-1b9bb1e1c008/internal/cmd/goal.go (about)

     1  package cmd
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/beauknowssoftware/makehcl/internal/targets"
     7  	"github.com/jessevdk/go-flags"
     8  )
     9  
    10  type Target string
    11  
    12  func (t *Target) Complete(match string) []flags.Completion {
    13  	var o targets.DoOptions
    14  	o.Sort = true
    15  
    16  	ts, err := targets.Do(o)
    17  	if err != nil {
    18  		return []flags.Completion{}
    19  	}
    20  
    21  	res := make([]flags.Completion, 0, len(ts))
    22  
    23  	for _, t := range ts {
    24  		if strings.HasPrefix(t, match) {
    25  			res = append(res, flags.Completion{
    26  				Item: t,
    27  			})
    28  		}
    29  	}
    30  
    31  	return res
    32  }
    33  
    34  type Goal struct {
    35  	Targets []Target
    36  }
    37  
    38  func (g Goal) strings() []string {
    39  	res := make([]string, len(g.Targets))
    40  	for i, t := range g.Targets {
    41  		res[i] = string(t)
    42  	}
    43  
    44  	return res
    45  }