Skip to content

Commit 9029102

Browse files
committed
feat(network-area): add async output handling
1 parent e0ca2d7 commit 9029102

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

internal/cmd/network-area/region/create/create.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
117117
s.Stop()
118118
}
119119

120-
return outputResult(params.Printer, model.OutputFormat, model.Region, networkAreaLabel, *resp)
120+
return outputResult(params.Printer, model.OutputFormat, model.Async, model.Region, networkAreaLabel, *resp)
121121
},
122122
}
123123
configureFlags(cmd)
@@ -186,9 +186,13 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
186186
return req.CreateNetworkAreaRegionPayload(payload)
187187
}
188188

189-
func outputResult(p *print.Printer, outputFormat, region, networkAreaLabel string, regionalArea iaas.RegionalArea) error {
189+
func outputResult(p *print.Printer, outputFormat string, async bool, region, networkAreaLabel string, regionalArea iaas.RegionalArea) error {
190190
return p.OutputResult(outputFormat, regionalArea, func() error {
191-
p.Outputf("Create region configuration for SNA %q.\nRegion: %s\n", networkAreaLabel, region)
191+
operationState := "Created"
192+
if async {
193+
operationState = "Triggered creation of"
194+
}
195+
p.Outputf("%s region configuration for SNA %q.\nRegion: %s\n", operationState, networkAreaLabel, region)
192196
return nil
193197
})
194198
}

internal/cmd/network-area/region/create/create_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ func TestBuildRequest(t *testing.T) {
267267
func Test_outputResult(t *testing.T) {
268268
type args struct {
269269
outputFormat string
270+
async bool
270271
region string
271272
networkAreaLabel string
272273
regionalArea iaas.RegionalArea
@@ -300,7 +301,7 @@ func Test_outputResult(t *testing.T) {
300301
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
301302
for _, tt := range tests {
302303
t.Run(tt.name, func(t *testing.T) {
303-
if err := outputResult(p, tt.args.outputFormat, tt.args.region, tt.args.networkAreaLabel, tt.args.regionalArea); (err != nil) != tt.wantErr {
304+
if err := outputResult(p, tt.args.outputFormat, tt.args.async, tt.args.region, tt.args.networkAreaLabel, tt.args.regionalArea); (err != nil) != tt.wantErr {
304305
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
305306
}
306307
})

0 commit comments

Comments
 (0)