github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/command/flag/deployment_strategy.go (about)

     1  package flag
     2  
     3  import (
     4  	"strings"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
     7  	"github.com/jessevdk/go-flags"
     8  )
     9  
    10  type DeploymentStrategy struct {
    11  	Name constant.DeploymentStrategy
    12  }
    13  
    14  func (DeploymentStrategy) Complete(prefix string) []flags.Completion {
    15  	return completions([]string{string(constant.DeploymentStrategyRolling)}, prefix, false)
    16  }
    17  
    18  func (h *DeploymentStrategy) UnmarshalFlag(val string) error {
    19  	valLower := strings.ToLower(val)
    20  
    21  	switch valLower {
    22  
    23  	case string(constant.DeploymentStrategyDefault):
    24  		// Do nothing, leave the default value
    25  
    26  	case string(constant.DeploymentStrategyRolling):
    27  		h.Name = constant.DeploymentStrategy(valLower)
    28  
    29  	default:
    30  		return &flags.Error{
    31  			Type:    flags.ErrInvalidChoice,
    32  			Message: `STRATEGY must be "rolling" or not set`,
    33  		}
    34  	}
    35  
    36  	return nil
    37  }