github.com/loafoe/cli@v7.1.0+incompatible/cf/requirements/login.go (about)

     1  package requirements
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
     7  	"code.cloudfoundry.org/cli/cf/terminal"
     8  )
     9  
    10  type LoginRequirement struct {
    11  	config                 coreconfig.Reader
    12  	apiEndpointRequirement APIEndpointRequirement
    13  }
    14  
    15  func NewLoginRequirement(config coreconfig.Reader) LoginRequirement {
    16  	return LoginRequirement{config, APIEndpointRequirement{config}}
    17  }
    18  
    19  func (req LoginRequirement) Execute() error {
    20  
    21  	if err := req.apiEndpointRequirement.Execute(); err != nil {
    22  		return err
    23  	}
    24  
    25  	if !req.config.IsLoggedIn() {
    26  		return errors.New(terminal.NotLoggedInText())
    27  	}
    28  
    29  	return nil
    30  }