@@ -24,12 +24,13 @@ const (
2424 environmentIDFlag = "environment-id"
2525 nameFlag = "name"
2626 // Container config
27- imageFlag = "image"
28- cpuFlag = "cpu"
29- memoryFlag = "memory"
30- envVarsFlag = "environment-vars"
31- commandsFlag = "commands"
32- argsFlag = "args"
27+ containerNameFlag = "container-name"
28+ imageFlag = "image"
29+ cpuFlag = "cpu"
30+ memoryFlag = "memory"
31+ envVarsFlag = "environment-vars"
32+ commandsFlag = "commands"
33+ argsFlag = "args"
3334 // Scaling
3435 instancesFlag = "instances"
3536 minInstancesFlag = "min-instances"
@@ -40,9 +41,7 @@ const (
4041 // Networking
4142 publicFlag = "public"
4243 externalPortFlag = "external-port"
43- )
4444
45- const (
4645 scalingTypeManual = "manual"
4746 scalingTypeAuto = "auto"
4847
@@ -65,6 +64,7 @@ type inputModel struct {
6564 * globalflags.GlobalFlagModel
6665 EnvironmentID string
6766 Name string
67+ ContainerName string
6868 Image string
6969 CPU int32
7070 Memory int32
@@ -86,7 +86,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8686 cmd := & cobra.Command {
8787 Use : "create" ,
8888 Short : "Create a SCA application" ,
89- Long : "Create a STACKIT Kubernetes Engine (SCA) application." ,
89+ Long : "Create a STACKIT Container Applications (SCA) application." ,
9090 Args : args .NoArgs ,
9191 Example : examples .Build (
9292 examples .NewExample (
@@ -97,7 +97,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
9797 "$ stackit alpha sca application create --name application-name --image my-image --instances 2" ),
9898 examples .NewExample (
9999 `Create a SCA application with name "application-name" and image "my-image" exposing port 8888 of the container` ,
100- "$ stackit alpha sca application create --name application-name --image my-image --port 8888" ),
100+ "$ stackit alpha sca application create --name application-name --image my-image --external- port 8888" ),
101101 examples .NewExample (
102102 `Create a SCA application with name "application-name" and image "my-image" disabling public networking` ,
103103 "$ stackit alpha sca application create --name application-name --image my-image --public=false" ),
@@ -141,9 +141,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
141141 }
142142 }
143143
144- outputResult (params .Printer , model , resp )
145-
146- return nil
144+ return outputResult (params .Printer , model , resp )
147145 },
148146 }
149147
@@ -217,19 +215,26 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *sca.APIClie
217215 CreateApplicationPayload (payload )
218216}
219217
220- func outputResult (p * print.Printer , model * inputModel , application * sca.Application ) {
221- operationState := "Created"
222- if model .Async {
223- operationState = "Triggered creation of"
218+ func outputResult (p * print.Printer , model * inputModel , application * sca.Application ) error {
219+ if application == nil {
220+ return fmt .Errorf ("create application response is empty" )
224221 }
225222
226- p .Outputf ("%s application for environment %s. Application ID: %s\n " , operationState , application .GetEnvironmentId (), application .GetId ())
223+ return p .OutputResult (model .OutputFormat , application , func () error {
224+ operationState := "Created"
225+ if model .Async {
226+ operationState = "Triggered creation of"
227+ }
228+ p .Outputf ("%s application for environment %s. Application ID: %s\n " , operationState , application .GetEnvironmentId (), application .GetId ())
229+ return nil
230+ })
227231}
228232
229233func configureFlags (cmd * cobra.Command ) {
230234 cmd .Flags ().Var (flags .UUIDFlag (), environmentIDFlag , "Environment ID (uses default environment if not set)" )
231235 cmd .Flags ().String (nameFlag , "" , "Application display name" )
232236 // container
237+ cmd .Flags ().String (containerNameFlag , defaultContainerName , "Container name" )
233238 cmd .Flags ().String (imageFlag , "" , "Container image" )
234239 cmd .Flags ().Int32 (cpuFlag , defaultCPU , "The dedicated virtual CPU processing power allocated per container instance" )
235240 cmd .Flags ().Int32 (memoryFlag , defaultMemory , "The total amount of memory (RAM) allocated per container instance" )
@@ -240,7 +245,7 @@ func configureFlags(cmd *cobra.Command) {
240245 scalingTypeFlag .Register (cmd .Flags ())
241246 cmd .Flags ().Int32 (instancesFlag , defaultInstances , "The number of application instances (if manually scaled)" )
242247 cmd .Flags ().Int32 (minInstancesFlag , 1 , "The minimum number of application instances (if autoscaling is enabled)" )
243- cmd .Flags ().Int32 (maxInstancesFlag , 1 , "The maximum number of application instances (if autoscaling is enabled)" )
248+ cmd .Flags ().Int32 (maxInstancesFlag , 0 , "The maximum number of application instances (if autoscaling is enabled)" )
244249 cmd .Flags ().Int32 (rpsFlag , 0 , "Target number of requests per second to trigger autoscaling (if autoscaling is enabled)" )
245250 cmd .Flags ().Int32 (concurrencyFlag , 0 , "Target number of in-flight requests to trigger autoscaling (if autoscaling is enabled)" )
246251 cmd .Flags ().Bool (scaleToZeroFlag , false , "Enable scale to zero (if autoscaling is enabled)" )
@@ -283,11 +288,11 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
283288 }
284289 }
285290
286- maxInstances := flags . FlagWithDefaultToInt32Value ( p , cmd , maxInstancesFlag )
287- if maxInstances == 0 {
288- maxInstances = minInstances
291+ maxInstances := minInstances
292+ if i := flags . FlagToInt32Pointer ( p , cmd , maxInstancesFlag ); i != nil {
293+ maxInstances = * i
289294 }
290- if maxInstances < minInstances || minInstances > 10 {
295+ if maxInstances < minInstances || maxInstances > 10 {
291296 return nil , & errors.FlagValidationError {
292297 Flag : minInstancesFlag ,
293298 Details : fmt .Sprintf ("must be an integer between minInstances (%d) and 10" , minInstances ),
@@ -303,10 +308,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
303308 }
304309
305310 cpu := flags .FlagWithDefaultToInt32Value (p , cmd , cpuFlag )
306- if cpu % 1000 != 0 {
311+ if cpu <= 0 || cpu % 1000 != 0 {
307312 return nil , & errors.FlagValidationError {
308- Flag : instancesFlag ,
309- Details : "must be divisible by 1000" ,
313+ Flag : cpuFlag ,
314+ Details : "must be a valid value divisible by 1000" ,
310315 }
311316 }
312317
@@ -324,6 +329,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
324329 GlobalFlagModel : globalFlags ,
325330 EnvironmentID : environmentID ,
326331 Name : flags .FlagToStringValue (p , cmd , nameFlag ),
332+ ContainerName : flags .FlagWithDefaultToStringValue (p , cmd , containerNameFlag ),
327333 Image : flags .FlagToStringValue (p , cmd , imageFlag ),
328334 CPU : cpu ,
329335 Memory : flags .FlagWithDefaultToInt32Value (p , cmd , memoryFlag ),
0 commit comments