github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/requirements/buildpack.go (about)

     1  package requirements
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/cf/api"
     5  	"code.cloudfoundry.org/cli/cf/models"
     6  )
     7  
     8  //go:generate counterfeiter . BuildpackRequirement
     9  
    10  type BuildpackRequirement interface {
    11  	Requirement
    12  	GetBuildpack() models.Buildpack
    13  }
    14  
    15  type buildpackAPIRequirement struct {
    16  	name          string
    17  	stack         string
    18  	buildpackRepo api.BuildpackRepository
    19  	buildpack     models.Buildpack
    20  }
    21  
    22  func NewBuildpackRequirement(name, stack string, bR api.BuildpackRepository) (req *buildpackAPIRequirement) {
    23  	req = new(buildpackAPIRequirement)
    24  	req.name = name
    25  	req.stack = stack
    26  	req.buildpackRepo = bR
    27  	return
    28  }
    29  
    30  func (req *buildpackAPIRequirement) Execute() error {
    31  	var apiErr error
    32  	if req.stack == "" {
    33  		req.buildpack, apiErr = req.buildpackRepo.FindByName(req.name)
    34  	} else {
    35  		req.buildpack, apiErr = req.buildpackRepo.FindByNameAndStack(req.name, req.stack)
    36  	}
    37  
    38  	if apiErr != nil {
    39  		return apiErr
    40  	}
    41  
    42  	return nil
    43  }
    44  
    45  func (req *buildpackAPIRequirement) GetBuildpack() models.Buildpack {
    46  	return req.buildpack
    47  }