github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/requirements/diego_application.go (about)

     1  package requirements
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/cf/api/applications"
     5  	"code.cloudfoundry.org/cli/cf/errors"
     6  	"code.cloudfoundry.org/cli/cf/models"
     7  	"code.cloudfoundry.org/cli/cf/terminal"
     8  )
     9  
    10  //go:generate counterfeiter . DiegoApplicationRequirement
    11  
    12  type DiegoApplicationRequirement interface {
    13  	Requirement
    14  	GetApplication() models.Application
    15  }
    16  
    17  type diegoApplicationRequirement struct {
    18  	appName string
    19  	ui      terminal.UI
    20  	appRepo applications.Repository
    21  
    22  	application models.Application
    23  }
    24  
    25  func NewDiegoApplicationRequirement(name string, applicationRepo applications.Repository) DiegoApplicationRequirement {
    26  	return &diegoApplicationRequirement{
    27  		appName: name,
    28  		appRepo: applicationRepo,
    29  	}
    30  }
    31  
    32  func (req *diegoApplicationRequirement) Execute() error {
    33  	app, err := req.appRepo.Read(req.appName)
    34  	if err != nil {
    35  		return err
    36  	}
    37  
    38  	if app.Diego == false {
    39  		return errors.New("The app is running on the DEA backend, which does not support this command.")
    40  	}
    41  
    42  	req.application = app
    43  
    44  	return nil
    45  }
    46  
    47  func (req *diegoApplicationRequirement) GetApplication() models.Application {
    48  	return req.application
    49  }