@@ -318,7 +318,10 @@ func (h *ServiceHandler) addServiceDefinitionFlagsForAllSources(flags *pflag.Fla
318
318
"To delete an environment variable, prefix its name with '!', for example --env '!FOO'\n " ,
319
319
)
320
320
flags .String ("instance-type" , "nano" , "Instance type" )
321
- flags .String ("deployment-strategy" , "rolling" , "Deployment strategy" )
321
+
322
+ var strategy DeploymentStrategy
323
+ flags .Var (& strategy , "deployment-strategy" , "Deployment strategy" )
324
+
322
325
flags .Int64 ("scale" , 1 , "Set both min-scale and max-scale" )
323
326
flags .Int64 ("min-scale" , 1 , "Min scale" )
324
327
flags .Int64 ("max-scale" , 1 , "Max scale" )
@@ -594,45 +597,13 @@ func (h *ServiceHandler) parseInstanceType(flags *pflag.FlagSet, currentInstance
594
597
// Parse --deployment-strategy
595
598
func (h * ServiceHandler ) parseDeploymentStrategy (flags * pflag.FlagSet , currentStrategy koyeb.DeploymentStrategy ) (koyeb.DeploymentStrategy , error ) {
596
599
if ! flags .Lookup ("deployment-strategy" ).Changed {
597
- // New service: return the default value
598
- if currentStrategy .Type == nil {
599
- value := flags .Lookup ("deployment-strategy" ).DefValue
600
- enum := fmt .Sprintf ("DEPLOYMENT_STRATEGY_TYPE_%s" , strings .ToUpper (strings .ReplaceAll (value , "-" , "_" )))
601
- kind , err := koyeb .NewDeploymentStrategyTypeFromValue (enum )
602
- if err != nil {
603
- panic (err )
604
- }
605
- ret := koyeb.DeploymentStrategy {
606
- Type : kind ,
607
- }
608
- return ret , nil
609
- }
610
- // Existing service: return the strategy currently configured
611
600
return currentStrategy , nil
612
601
}
613
-
614
- value , _ := flags .GetString ("deployment-strategy" )
615
- enum := fmt .Sprintf ("DEPLOYMENT_STRATEGY_TYPE_%s" , strings .ToUpper (strings .ReplaceAll (value , "-" , "_" )))
616
- kind , err := koyeb .NewDeploymentStrategyTypeFromValue (enum )
617
- if err != nil {
618
- return koyeb.DeploymentStrategy {}, & errors.CLIError {
619
- What : "Error while updating the service" ,
620
- Why : "the --deployment-strategy flag is not valid" ,
621
- Additional : []string {
622
- "The --deployment-strategy flag must be one of the following:" ,
623
- " - rolling" ,
624
- " - canary" ,
625
- " - blue-green" ,
626
- " - immediate" ,
627
- },
628
- Orig : nil ,
629
- Solution : "Fix the --deployment-strategy flag and try again" ,
630
- }
631
- }
632
- ret := koyeb.DeploymentStrategy {
633
- Type : kind ,
634
- }
635
- return ret , nil
602
+ flagValue := flags .Lookup ("deployment-strategy" ).Value .(* DeploymentStrategy )
603
+ strategy := koyeb .DeploymentStrategyType (* flagValue )
604
+ return koyeb.DeploymentStrategy {
605
+ Type : & strategy ,
606
+ }, nil
636
607
}
637
608
638
609
// parseListFlags is the generic function parsing --env, --port, --routes, --checks, --regions and --volumes
@@ -1753,3 +1724,30 @@ func (h *ServiceHandler) parseVolumes(ctx *CLIContext, flags *pflag.FlagSet, cur
1753
1724
1754
1725
return parseListFlags ("volumes" , flags_list .GetNewVolumeListFromFlags (wrappedResolveVolumeId ), flags , currentVolumes )
1755
1726
}
1727
+
1728
+ // DeploymentStrategy is a type alias for koyeb.DeploymentStrategyType which implements the pflag.Value interface.
1729
+ type DeploymentStrategy koyeb.DeploymentStrategyType
1730
+
1731
+ func (s * DeploymentStrategy ) String () string {
1732
+ return string (* s )
1733
+ }
1734
+
1735
+ func (s * DeploymentStrategy ) Set (value string ) error {
1736
+ switch value {
1737
+ case "rolling" :
1738
+ * s = DeploymentStrategy (koyeb .DEPLOYMENTSTRATEGYTYPE_ROLLING )
1739
+ case "canary" :
1740
+ * s = DeploymentStrategy (koyeb .DEPLOYMENTSTRATEGYTYPE_CANARY )
1741
+ case "blue-green" :
1742
+ * s = DeploymentStrategy (koyeb .DEPLOYMENTSTRATEGYTYPE_BLUE_GREEN )
1743
+ case "immediate" :
1744
+ * s = DeploymentStrategy (koyeb .DEPLOYMENTSTRATEGYTYPE_IMMEDIATE )
1745
+ default :
1746
+ return fmt .Errorf ("invalid deployment strategy: %s. Valid values are: rolling, canary, blue-green, immediate." , value )
1747
+ }
1748
+ return nil
1749
+ }
1750
+
1751
+ func (s * DeploymentStrategy ) Type () string {
1752
+ return "deployment-strategy"
1753
+ }
0 commit comments