Skip to content

Commit 45d8640

Browse files
author
Syeda Haya Fatima
committed
Fixed region and output response, STACKITMLO-1718
1 parent dcc8499 commit 45d8640

13 files changed

Lines changed: 57 additions & 34 deletions

File tree

internal/cmd/modelexperiments/instance/create/create.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ type inputModel struct {
3333
Description *string
3434
Labels *map[string]string
3535
Retention *string
36-
Region string
3736
}
3837

3938
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -117,15 +116,14 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
117116
Description: flags.FlagToStringPointer(p, cmd, descriptionFlag),
118117
Labels: labelsPtr,
119118
Retention: flags.FlagToStringPointer(p, cmd, retentionFlag),
120-
Region: flags.FlagToStringValue(p, cmd, globalflags.RegionFlag),
121119
}
122120

123121
p.DebugInputModel(model)
124122
return &model, nil
125123
}
126124

127125
func buildCreateInstanceRequest(ctx context.Context, model *inputModel, apiClient *modelexperiments.APIClient) modelexperiments.ApiCreateInstanceRequest {
128-
req := apiClient.DefaultAPI.CreateInstance(ctx, model.ProjectId, model.Region)
126+
req := apiClient.DefaultAPI.CreateInstance(ctx, model.ProjectId, model.GlobalFlagModel.Region)
129127

130128
payload := modelexperiments.CreateInstancePayload{
131129
Name: model.Name,

internal/cmd/modelexperiments/instance/create/create_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4545
Region: "eu01",
4646
Verbosity: globalflags.VerbosityDefault,
4747
},
48-
Name: "example",
49-
Region: "eu01",
48+
Name: "example",
5049
}
5150
for _, mod := range mods {
5251
mod(model)

internal/cmd/modelexperiments/instance/delete/delete.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1010
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1111
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
12-
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1312
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1413
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1514
"github.com/stackitcloud/stackit-cli/internal/pkg/services/modelexperiments/client"
@@ -26,7 +25,6 @@ const (
2625
type inputModel struct {
2726
*globalflags.GlobalFlagModel
2827
InstanceId string
29-
Region string
3028
}
3129

3230
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -80,7 +78,6 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
8078
}
8179

8280
func configureFlags(cmd *cobra.Command) {
83-
_ = flags.MarkFlagsRequired(cmd, globalflags.RegionFlag)
8481
}
8582

8683
func parseInput(
@@ -97,7 +94,6 @@ func parseInput(
9794
model := inputModel{
9895
GlobalFlagModel: globalFlags,
9996
InstanceId: inputArgs[0],
100-
Region: flags.FlagToStringValue(p, cmd, globalflags.RegionFlag),
10197
}
10298

10399
p.DebugInputModel(model)
@@ -113,7 +109,7 @@ func buildDeleteInstanceRequest(
113109
return apiClient.DefaultAPI.DeleteInstance(
114110
ctx,
115111
model.ProjectId,
116-
model.Region,
112+
model.GlobalFlagModel.Region,
117113
model.InstanceId,
118114
)
119115
}

internal/cmd/modelexperiments/instance/delete/delete_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func fixtureInputModel(
5353
Verbosity: globalflags.VerbosityDefault,
5454
},
5555
InstanceId: testInstanceId,
56-
Region: "eu01",
5756
}
5857

5958
for _, mod := range mods {

internal/cmd/modelexperiments/instance/get/get.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1010
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1111
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
12-
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1312
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1413
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1514
"github.com/stackitcloud/stackit-cli/internal/pkg/services/modelexperiments/client"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
1616
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1717
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1818

@@ -26,7 +26,6 @@ const (
2626
type inputModel struct {
2727
*globalflags.GlobalFlagModel
2828
InstanceId string
29-
Region string
3029
}
3130

3231
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -71,7 +70,6 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7170
}
7271

7372
func configureFlags(cmd *cobra.Command) {
74-
_ = flags.MarkFlagsRequired(cmd, globalflags.RegionFlag)
7573
}
7674

7775
func parseInput(
@@ -88,7 +86,6 @@ func parseInput(
8886
model := inputModel{
8987
GlobalFlagModel: globalFlags,
9088
InstanceId: inputArgs[0],
91-
Region: flags.FlagToStringValue(p, cmd, globalflags.RegionFlag),
9289
}
9390

9491
p.DebugInputModel(model)
@@ -104,7 +101,7 @@ func buildGetInstanceRequest(
104101
return apiClient.DefaultAPI.GetInstance(
105102
ctx,
106103
model.ProjectId,
107-
model.Region,
104+
model.GlobalFlagModel.Region,
108105
model.InstanceId,
109106
)
110107
}
@@ -119,6 +116,14 @@ func outputResult(
119116
}
120117

121118
return p.OutputResult(outputFormat, resp.Instance, func() error {
122-
return nil
119+
table := tables.NewTable()
120+
table.SetHeader("ID", "NAME", "REGION", "STATUS")
121+
table.AddRow(
122+
resp.Instance.Id,
123+
resp.Instance.Name,
124+
resp.Instance.Region,
125+
resp.Instance.State,
126+
)
127+
return table.Display(p)
123128
})
124129
}

internal/cmd/modelexperiments/instance/get/get_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func fixtureInputModel(
5353
Verbosity: globalflags.VerbosityDefault,
5454
},
5555
InstanceId: testInstanceId,
56-
Region: "eu01",
5756
}
5857

5958
for _, mod := range mods {

internal/cmd/modelexperiments/instance/list/list.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ import (
99
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1010
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1111
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
12-
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1312
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1413
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1514
"github.com/stackitcloud/stackit-cli/internal/pkg/services/modelexperiments/client"
15+
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
1616
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
1717

1818
modelexperiments "github.com/stackitcloud/stackit-sdk-go/services/modelexperiments/v1api"
1919
)
2020

2121
type inputModel struct {
2222
*globalflags.GlobalFlagModel
23-
Region string
2423
}
2524

2625
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -65,7 +64,6 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6564
}
6665

6766
func configureFlags(cmd *cobra.Command) {
68-
_ = flags.MarkFlagsRequired(cmd, globalflags.RegionFlag)
6967
}
7068

7169
func parseInput(
@@ -81,7 +79,6 @@ func parseInput(
8179

8280
model := inputModel{
8381
GlobalFlagModel: globalFlags,
84-
Region: flags.FlagToStringValue(p, cmd, globalflags.RegionFlag),
8582
}
8683

8784
p.DebugInputModel(model)
@@ -97,7 +94,7 @@ func buildListInstancesRequest(
9794
return apiClient.DefaultAPI.ListInstances(
9895
ctx,
9996
model.ProjectId,
100-
model.Region,
97+
model.GlobalFlagModel.Region,
10198
)
10299
}
103100

@@ -111,6 +108,23 @@ func outputResult(
111108
}
112109

113110
return p.OutputResult(outputFormat, resp.Instances, func() error {
114-
return nil
111+
if len(resp.Instances) == 0 {
112+
p.Outputf("No instances found\n")
113+
return nil
114+
}
115+
116+
table := tables.NewTable()
117+
table.SetHeader("ID", "NAME", "REGION", "STATUS")
118+
119+
for _, instance := range resp.Instances {
120+
table.AddRow(
121+
instance.Id,
122+
instance.Name,
123+
instance.Region,
124+
instance.State,
125+
)
126+
}
127+
128+
return table.Display(p)
115129
})
116130
}

internal/cmd/modelexperiments/instance/list/list_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ func fixtureInputModel(
5151
Region: "eu01",
5252
Verbosity: globalflags.VerbosityDefault,
5353
},
54-
Region: "eu01",
5554
}
5655

5756
for _, mod := range mods {

internal/cmd/modelexperiments/instance/patch/patch.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ type inputModel struct {
3737
Description *string
3838
Labels *map[string]*string
3939
Retention *string
40-
41-
Region string
4240
}
4341

4442
func NewCmd(params *types.CmdParams) *cobra.Command {
@@ -139,8 +137,6 @@ func parseInput(
139137
Description: flags.FlagToStringPointer(p, cmd, descriptionFlag),
140138
Labels: labelsPtr,
141139
Retention: flags.FlagToStringPointer(p, cmd, retentionFlag),
142-
143-
Region: flags.FlagToStringValue(p, cmd, globalflags.RegionFlag),
144140
}
145141

146142
if model.Name == nil &&
@@ -163,7 +159,7 @@ func buildPatchInstanceRequest(
163159
req := apiClient.DefaultAPI.PartialUpdateInstance(
164160
ctx,
165161
model.ProjectId,
166-
model.Region,
162+
model.GlobalFlagModel.Region,
167163
model.InstanceId,
168164
)
169165

internal/cmd/modelexperiments/instance/patch/patch_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func fixtureInputModel(
5454
Verbosity: globalflags.VerbosityDefault,
5555
},
5656
InstanceId: testInstanceId,
57-
Region: "eu01",
5857
}
5958

6059
for _, mod := range mods {

0 commit comments

Comments
 (0)