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

     1  package requirements
     2  
     3  import "code.cloudfoundry.org/cli/cf/configuration/coreconfig"
     4  
     5  type configRefreshingRequirement struct {
     6  	requirement     Requirement
     7  	configRefresher ConfigRefresher
     8  }
     9  
    10  //go:generate counterfeiter . ConfigRefresher
    11  
    12  type ConfigRefresher interface {
    13  	Refresh() (coreconfig.Warning, error)
    14  }
    15  
    16  func NewConfigRefreshingRequirement(requirement Requirement, configRefresher ConfigRefresher) configRefreshingRequirement {
    17  	return configRefreshingRequirement{
    18  		requirement:     requirement,
    19  		configRefresher: configRefresher,
    20  	}
    21  }
    22  
    23  func (c configRefreshingRequirement) Execute() error {
    24  	err := c.requirement.Execute()
    25  	if err != nil {
    26  		// Do the config refresh
    27  		_, err = c.configRefresher.Refresh()
    28  		if err != nil {
    29  			return err
    30  		}
    31  
    32  		return c.requirement.Execute()
    33  	}
    34  
    35  	return nil
    36  }