@@ -19,30 +19,36 @@ import (
1919
2020const (
2121 formatFlag = "format"
22+ typeFlag = "type"
2223)
2324
2425type inputModel struct {
2526 * globalflags.GlobalFlagModel
2627 Format * string
28+ Type * string
2729}
2830
29- //go:embed template.json
30- var template string
31+ var (
32+ //go:embed template-alb.json
33+ templateAlb string
34+ //go:embed template-pool.json
35+ templatePool string
36+ )
3137
3238func NewCmd (p * print.Printer ) * cobra.Command {
3339 cmd := & cobra.Command {
3440 Use : "template" ,
35- Short : "create an alb template " ,
36- Long : "creates a json or yaml template file for creating/updating an application loadbalancer." ,
41+ Short : "creates configuration templates to use for resource creation " ,
42+ Long : "creates a json or yaml template file for creating/updating an application loadbalancer or target pool ." ,
3743 Args : args .NoArgs ,
3844 Example : examples .Build (
3945 examples .NewExample (
40- `Creat a yaml template` ,
41- `$ stackit beta alb template --format=yaml` ,
46+ `Create a yaml template` ,
47+ `$ stackit beta alb template --format=yaml --type alb ` ,
4248 ),
4349 examples .NewExample (
44- `Creat a json template` ,
45- `$ stackit beta alb template --format=json` ,
50+ `Create a json template` ,
51+ `$ stackit beta alb template --format=json --type pool ` ,
4652 ),
4753 ),
4854 RunE : func (cmd * cobra.Command , _ []string ) error {
@@ -51,10 +57,21 @@ func NewCmd(p *print.Printer) *cobra.Command {
5157 return err
5258 }
5359
60+ var (
61+ template string
62+ target any
63+ )
64+ if model .Type != nil && * model .Type == "pool" {
65+ template = templatePool
66+ target = alb.CreateLoadBalancerPayload {}
67+ } else {
68+ template = templateAlb
69+ target = alb.UpdateTargetPoolPayload {}
70+ }
71+
5472 if model .Format == nil || * model .Format == "json" {
5573 p .Outputln (template )
5674 } else if * model .Format == "yaml" {
57- var target alb.CreateLoadBalancerPayload
5875 if err := json .Unmarshal ([]byte (template ), & target ); err != nil {
5976 return fmt .Errorf ("cannot unmarshal template: %w" , err )
6077 }
@@ -75,7 +92,8 @@ func NewCmd(p *print.Printer) *cobra.Command {
7592}
7693
7794func configureFlags (cmd * cobra.Command ) {
78- cmd .Flags ().VarP (flags .EnumFlag (true , "json" , "json" , "yaml" ), formatFlag , "f" , "Defines the output format (yaml or json), default is json" )
95+ cmd .Flags ().VarP (flags .EnumFlag (true , "json" , "json" , "yaml" ), formatFlag , "f" , "Defines the output format ('yaml' or 'json'), default is 'json'" )
96+ cmd .Flags ().VarP (flags .EnumFlag (true , "alb" , "alb" , "pool" ), typeFlag , "t" , "Defines the output type ('alb' or 'pool'), default is 'alb'" )
7997}
8098
8199func parseInput (p * print.Printer , cmd * cobra.Command ) (* inputModel , error ) {
@@ -87,6 +105,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
87105 model := inputModel {
88106 GlobalFlagModel : globalFlags ,
89107 Format : flags .FlagToStringPointer (p , cmd , formatFlag ),
108+ Type : flags .FlagToStringPointer (p , cmd , typeFlag ),
90109 }
91110
92111 if p .IsVerbosityDebug () {
0 commit comments