github.com/Thanhphan1147/cloudfoundry-cli@v7.1.0+incompatible/command/minimum_version_check.go (about)

     1  package command
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/command/translatableerror"
     5  	log "github.com/sirupsen/logrus"
     6  )
     7  
     8  func MinimumCCAPIVersionCheck(current string, minimum string, customCommand ...string) error {
     9  	log.WithFields(log.Fields{"current": current, "minimum": minimum}).Debug("minimum api version")
    10  	var command string
    11  	if len(customCommand) > 0 {
    12  		command = customCommand[0]
    13  	}
    14  
    15  	isOutdated, err := CheckVersionOutdated(current, minimum)
    16  	if err != nil {
    17  		return err
    18  	}
    19  
    20  	if isOutdated {
    21  		log.WithFields(log.Fields{"current": current, "minimum": minimum}).Error("minimum not met")
    22  		return translatableerror.MinimumCFAPIVersionNotMetError{
    23  			Command:        command,
    24  			CurrentVersion: current,
    25  			MinimumVersion: minimum,
    26  		}
    27  	}
    28  
    29  	return nil
    30  }
    31  
    32  func MinimumUAAAPIVersionCheck(current string, minimum string, customCommand ...string) error {
    33  	log.WithFields(log.Fields{"current": current, "minimum": minimum}).Debug("minimum api version")
    34  	var command string
    35  	if len(customCommand) > 0 {
    36  		command = customCommand[0]
    37  	}
    38  
    39  	isOutdated, err := CheckVersionOutdated(current, minimum)
    40  	if err != nil {
    41  		return err
    42  	}
    43  
    44  	if isOutdated {
    45  		log.WithFields(log.Fields{"current": current, "minimum": minimum}).Error("minimum not met")
    46  		return translatableerror.MinimumUAAAPIVersionNotMetError{
    47  			Command:        command,
    48  			MinimumVersion: minimum,
    49  		}
    50  	}
    51  
    52  	return nil
    53  }