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

     1  package flag
     2  
     3  import (
     4  	"strings"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
     7  
     8  	flags "github.com/jessevdk/go-flags"
     9  )
    10  
    11  type HealthCheckType struct {
    12  	Type constant.HealthCheckType
    13  }
    14  
    15  func (HealthCheckType) Complete(prefix string) []flags.Completion {
    16  	return completions([]string{string(constant.HTTP), string(constant.Port), string(constant.Process)}, prefix, false)
    17  }
    18  
    19  func (h *HealthCheckType) UnmarshalFlag(val string) error {
    20  	valLower := strings.ToLower(val)
    21  	switch valLower {
    22  	case string(constant.HTTP), string(constant.Port), string(constant.Process):
    23  		h.Type = constant.HealthCheckType(valLower)
    24  	default:
    25  		return &flags.Error{
    26  			Type:    flags.ErrRequired,
    27  			Message: `HEALTH_CHECK_TYPE must be "port", "process", or "http"`,
    28  		}
    29  	}
    30  	return nil
    31  }