github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/cf/requirements/application.go (about)

     1  package requirements
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/cf/api/applications"
     5  	"code.cloudfoundry.org/cli/cf/models"
     6  )
     7  
     8  //go:generate counterfeiter . ApplicationRequirement
     9  
    10  type ApplicationRequirement interface {
    11  	Requirement
    12  	GetApplication() models.Application
    13  }
    14  
    15  type applicationAPIRequirement struct {
    16  	name        string
    17  	appRepo     applications.Repository
    18  	application models.Application
    19  }
    20  
    21  func NewApplicationRequirement(name string, aR applications.Repository) *applicationAPIRequirement {
    22  	req := &applicationAPIRequirement{}
    23  	req.name = name
    24  	req.appRepo = aR
    25  	return req
    26  }
    27  
    28  func (req *applicationAPIRequirement) Execute() error {
    29  	var apiErr error
    30  	req.application, apiErr = req.appRepo.Read(req.name)
    31  
    32  	if apiErr != nil {
    33  		return apiErr
    34  	}
    35  
    36  	return nil
    37  }
    38  
    39  func (req *applicationAPIRequirement) GetApplication() models.Application {
    40  	return req.application
    41  }