github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/runners/deploy/step.go (about)

     1  package deploy
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/ActiveState/cli/internal/locale"
     7  )
     8  
     9  // Step is the --step flag for the --deploy command, it implements captain.FlagMarshaler
    10  type Step int
    11  
    12  const (
    13  	UnsetStep Step = iota
    14  	InstallStep
    15  	ConfigureStep
    16  	SymlinkStep
    17  	ReportStep
    18  )
    19  
    20  var StepMap = map[Step]string{
    21  	UnsetStep:     "unset",
    22  	InstallStep:   "install",
    23  	ConfigureStep: "configure",
    24  	SymlinkStep:   "symlink",
    25  	ReportStep:    "report",
    26  }
    27  
    28  func (t Step) String() string {
    29  	for k, v := range StepMap {
    30  		if k == t {
    31  			return v
    32  		}
    33  	}
    34  	return StepMap[UnsetStep]
    35  }
    36  
    37  func (t *Step) Set(value string) error {
    38  	for k, v := range StepMap {
    39  		if v == value && k != UnsetStep {
    40  			*t = k
    41  			return nil
    42  		}
    43  	}
    44  
    45  	return locale.NewInputError("err_invalid_step", "",
    46  		value,
    47  		strings.Join([]string{InstallStep.String(), ConfigureStep.String(), ReportStep.String()}, ", "), // allowed values
    48  	)
    49  }
    50  
    51  func (t *Step) Type() string {
    52  	return "step"
    53  }