diff --git a/internal/cmd/beta/image/create/create.go b/internal/cmd/beta/image/create/create.go index e02518b01..7b259010e 100644 --- a/internal/cmd/beta/image/create/create.go +++ b/internal/cmd/beta/image/create/create.go @@ -395,7 +395,7 @@ func outputResult(p *print.Printer, model *inputModel, resp *iaas.ImageCreateRes return nil default: - p.Outputf("Created image %q with id %s\n", model.Name, *model.Id) + p.Outputf("Created image %q with id %s\n", model.Name, utils.PtrString(model.Id)) return nil } } diff --git a/internal/cmd/beta/key-pair/create/create.go b/internal/cmd/beta/key-pair/create/create.go index 4626946b2..b4bd759bb 100644 --- a/internal/cmd/beta/key-pair/create/create.go +++ b/internal/cmd/beta/key-pair/create/create.go @@ -82,7 +82,7 @@ func NewCmd(p *print.Printer) *cobra.Command { return fmt.Errorf("create key pair: %w", err) } - return outputResult(p, model, resp) + return outputResult(p, model.GlobalFlagModel.OutputFormat, resp) }, } configureFlags(cmd) @@ -141,8 +141,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli return req.CreateKeyPairPayload(payload) } -func outputResult(p *print.Printer, model *inputModel, item *iaas.Keypair) error { - switch model.OutputFormat { +func outputResult(p *print.Printer, outputFormat string, item *iaas.Keypair) error { + if item == nil { + return fmt.Errorf("no key pair found") + } + + switch outputFormat { case print.JSONOutputFormat: details, err := json.MarshalIndent(item, "", " ") if err != nil { @@ -156,7 +160,10 @@ func outputResult(p *print.Printer, model *inputModel, item *iaas.Keypair) error } p.Outputln(string(details)) default: - p.Outputf("Created key pair %q.\nkey pair Fingerprint: %q\n", *item.Name, *item.Fingerprint) + p.Outputf("Created key pair %q.\nkey pair Fingerprint: %q\n", + utils.PtrString(item.Name), + utils.PtrString(item.Fingerprint), + ) } return nil } diff --git a/internal/cmd/beta/key-pair/create/create_test.go b/internal/cmd/beta/key-pair/create/create_test.go index adb0f90b7..f912892d5 100644 --- a/internal/cmd/beta/key-pair/create/create_test.go +++ b/internal/cmd/beta/key-pair/create/create_test.go @@ -194,3 +194,42 @@ func TestBuildRequest(t *testing.T) { }) } } + +func Test_outputResult(t *testing.T) { + type args struct { + item *iaas.Keypair + outputFormat string + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "empty", + args: args{ + item: nil, + outputFormat: "", + }, + wantErr: true, + }, + { + name: "base", + args: args{ + item: &iaas.Keypair{}, + outputFormat: "", + }, + wantErr: false, + }, + } + + p := print.NewPrinter() + p.Cmd = NewCmd(p) + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := outputResult(p, tt.args.outputFormat, tt.args.item); (err != nil) != tt.wantErr { + t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/internal/cmd/beta/key-pair/describe/describe.go b/internal/cmd/beta/key-pair/describe/describe.go index 7f7a8e7b6..85981bde3 100644 --- a/internal/cmd/beta/key-pair/describe/describe.go +++ b/internal/cmd/beta/key-pair/describe/describe.go @@ -6,6 +6,8 @@ import ( "fmt" "strings" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" @@ -69,7 +71,11 @@ func NewCmd(p *print.Printer) *cobra.Command { return fmt.Errorf("read key pair: %w", err) } - return outputResult(p, model.OutputFormat, model.PublicKey, resp) + if keypair := resp; keypair != nil { + return outputResult(p, model.OutputFormat, model.PublicKey, *keypair) + } + p.Outputln("No keypair found.") + return nil }, } configureFlags(cmd) @@ -107,7 +113,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli return apiClient.GetKeyPair(ctx, model.KeyPairName) } -func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool, keyPair *iaas.Keypair) error { +func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool, keyPair iaas.Keypair) error { switch outputFormat { case print.JSONOutputFormat: details, err := json.MarshalIndent(keyPair, "", " ") @@ -145,10 +151,10 @@ func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool, return nil } table := tables.NewTable() - table.AddRow("KEY PAIR NAME", *keyPair.Name) + table.AddRow("KEY PAIR NAME", utils.PtrString(keyPair.Name)) table.AddSeparator() - if *keyPair.Labels != nil && len(*keyPair.Labels) > 0 { + if keyPair.Labels != nil && len(*keyPair.Labels) > 0 { var labels []string for key, value := range *keyPair.Labels { labels = append(labels, fmt.Sprintf("%s: %s", key, value)) @@ -157,17 +163,21 @@ func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool, table.AddSeparator() } - table.AddRow("FINGERPRINT", *keyPair.Fingerprint) + table.AddRow("FINGERPRINT", utils.PtrString(keyPair.Fingerprint)) table.AddSeparator() - truncatedPublicKey := (*keyPair.PublicKey)[:maxLengthPublicKey] + "..." + truncatedPublicKey := "" + if keyPair.PublicKey != nil { + truncatedPublicKey = (*keyPair.PublicKey)[:maxLengthPublicKey] + "..." + } + table.AddRow("PUBLIC KEY", truncatedPublicKey) table.AddSeparator() - table.AddRow("CREATED AT", *keyPair.CreatedAt) + table.AddRow("CREATED AT", utils.PtrString(keyPair.CreatedAt)) table.AddSeparator() - table.AddRow("UPDATED AT", *keyPair.UpdatedAt) + table.AddRow("UPDATED AT", utils.PtrString(keyPair.UpdatedAt)) table.AddSeparator() p.Outputln(table.Render()) diff --git a/internal/cmd/beta/key-pair/describe/describe_test.go b/internal/cmd/beta/key-pair/describe/describe_test.go index 69add5828..46374b3c8 100644 --- a/internal/cmd/beta/key-pair/describe/describe_test.go +++ b/internal/cmd/beta/key-pair/describe/describe_test.go @@ -186,3 +186,35 @@ func TestBuildRequest(t *testing.T) { }) } } + +func Test_outputResult(t *testing.T) { + type args struct { + outputFormat string + showOnlyPublicKey bool + keyPair iaas.Keypair + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "base", + args: args{ + outputFormat: "", + showOnlyPublicKey: false, + keyPair: iaas.Keypair{}, + }, + wantErr: false, + }, + } + p := print.NewPrinter() + p.Cmd = NewCmd(p) + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := outputResult(p, tt.args.outputFormat, tt.args.showOnlyPublicKey, tt.args.keyPair); (err != nil) != tt.wantErr { + t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/internal/cmd/beta/key-pair/list/list.go b/internal/cmd/beta/key-pair/list/list.go index 469a332fe..b25e6d6f6 100644 --- a/internal/cmd/beta/key-pair/list/list.go +++ b/internal/cmd/beta/key-pair/list/list.go @@ -6,6 +6,8 @@ import ( "fmt" "strings" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -158,11 +160,19 @@ func outputResult(p *print.Printer, outputFormat string, keyPairs []iaas.Keypair keyPair := keyPairs[idx] var labels []string - for key, value := range *keyPair.Labels { - labels = append(labels, fmt.Sprintf("%s: %s", key, value)) + if keyPair.Labels != nil { + for key, value := range *keyPair.Labels { + labels = append(labels, fmt.Sprintf("%s: %s", key, value)) + } } - table.AddRow(*keyPair.Name, strings.Join(labels, ", "), *keyPair.Fingerprint, *keyPair.CreatedAt, *keyPair.UpdatedAt) + table.AddRow( + utils.PtrString(keyPair.Name), + strings.Join(labels, ", "), + utils.PtrString(keyPair.Fingerprint), + utils.PtrString(keyPair.CreatedAt), + utils.PtrString(keyPair.UpdatedAt), + ) } p.Outputln(table.Render()) diff --git a/internal/cmd/beta/key-pair/list/list_test.go b/internal/cmd/beta/key-pair/list/list_test.go index 99bedd4ba..8fa0a948f 100644 --- a/internal/cmd/beta/key-pair/list/list_test.go +++ b/internal/cmd/beta/key-pair/list/list_test.go @@ -186,3 +186,37 @@ func TestBuildRequest(t *testing.T) { }) } } + +func Test_outputResult(t *testing.T) { + type args struct { + outputFormat string + keyPairs []iaas.Keypair + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "empty", + args: args{ + outputFormat: "", + keyPairs: []iaas.Keypair{ + {}, + }, + }, + wantErr: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := print.NewPrinter() + p.Cmd = NewCmd(p) + + if err := outputResult(p, tt.args.outputFormat, tt.args.keyPairs); (err != nil) != tt.wantErr { + t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/internal/cmd/beta/key-pair/update/update.go b/internal/cmd/beta/key-pair/update/update.go index 39b6abacf..de9b9f5d4 100644 --- a/internal/cmd/beta/key-pair/update/update.go +++ b/internal/cmd/beta/key-pair/update/update.go @@ -43,10 +43,7 @@ func NewCmd(p *print.Printer) *cobra.Command { ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() - model, err := parseInput(p, cmd, args) - if err != nil { - return err - } + model := parseInput(p, cmd, args) // Configure API client apiClient, err := client.ConfigureClient(p) @@ -63,13 +60,16 @@ func NewCmd(p *print.Printer) *cobra.Command { } // Call API - req := buildRequest(ctx, model, apiClient) + req := buildRequest(ctx, &model, apiClient) resp, err := req.Execute() if err != nil { return fmt.Errorf("update key pair: %w", err) } + if resp == nil { + return fmt.Errorf("response is nil") + } - return outputResult(p, model, resp) + return outputResult(p, model, *resp) }, } configureFlags(cmd) @@ -100,7 +100,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli return req.UpdateKeyPairPayload(payload) } -func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) { +func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) inputModel { keyPairName := inputArgs[0] globalFlags := globalflags.Parse(p, cmd) @@ -119,11 +119,15 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu } } - return &model, nil + return model } -func outputResult(p *print.Printer, model *inputModel, keyPair *iaas.Keypair) error { - switch model.OutputFormat { +func outputResult(p *print.Printer, model inputModel, keyPair iaas.Keypair) error { + var outputFormat string + if model.GlobalFlagModel != nil { + outputFormat = model.GlobalFlagModel.OutputFormat + } + switch outputFormat { case print.JSONOutputFormat: details, err := json.MarshalIndent(keyPair, "", " ") if err != nil { @@ -137,7 +141,7 @@ func outputResult(p *print.Printer, model *inputModel, keyPair *iaas.Keypair) er } p.Outputln(string(details)) default: - p.Outputf("Updated labels of key pair %q\n", *model.KeyPairName) + p.Outputf("Updated labels of key pair %q\n", utils.PtrString(model.KeyPairName)) } return nil } diff --git a/internal/cmd/beta/key-pair/update/update_test.go b/internal/cmd/beta/key-pair/update/update_test.go index 49d6aeabb..5743e2d60 100644 --- a/internal/cmd/beta/key-pair/update/update_test.go +++ b/internal/cmd/beta/key-pair/update/update_test.go @@ -141,18 +141,12 @@ func TestParseInput(t *testing.T) { t.Fatalf("error validating args: %v", err) } - model, err := parseInput(p, cmd, tt.argValues) - if err != nil { - if !tt.isValid { - return - } - t.Fatalf("error parsing flags: %v", err) - } + model := parseInput(p, cmd, tt.argValues) if !tt.isValid { t.Fatalf("did not fail on invalid input") } - diff := cmp.Diff(model, tt.expectedModel) + diff := cmp.Diff(&model, tt.expectedModel) if diff != "" { t.Fatalf("Data does not match: %s", diff) } @@ -188,3 +182,38 @@ func TestBuildRequest(t *testing.T) { }) } } + +func Test_outputResult(t *testing.T) { + type args struct { + model inputModel + keyPair iaas.Keypair + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + name: "empty", + args: args{}, + wantErr: false, + }, + { + name: "base", + args: args{ + model: inputModel{}, + keyPair: iaas.Keypair{}, + }, + wantErr: false, + }, + } + p := print.NewPrinter() + p.Cmd = NewCmd(p) + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := outputResult(p, tt.args.model, tt.args.keyPair); (err != nil) != tt.wantErr { + t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/internal/cmd/beta/network-area/create/create.go b/internal/cmd/beta/network-area/create/create.go index 83322226b..576fd8904 100644 --- a/internal/cmd/beta/network-area/create/create.go +++ b/internal/cmd/beta/network-area/create/create.go @@ -197,7 +197,7 @@ func outputResult(p *print.Printer, model *inputModel, orgLabel string, networkA return nil default: - p.Outputf("Created STACKIT Network Area for organization %q.\nNetwork area ID: %s\n", orgLabel, *networkArea.AreaId) + p.Outputf("Created STACKIT Network Area for organization %q.\nNetwork area ID: %s\n", orgLabel, utils.PtrString(networkArea.AreaId)) return nil } } diff --git a/internal/cmd/beta/network-area/describe/describe.go b/internal/cmd/beta/network-area/describe/describe.go index 1332572a6..61c329af9 100644 --- a/internal/cmd/beta/network-area/describe/describe.go +++ b/internal/cmd/beta/network-area/describe/describe.go @@ -160,11 +160,11 @@ func outputResult(p *print.Printer, outputFormat string, networkArea *iaas.Netwo } table := tables.NewTable() - table.AddRow("ID", *networkArea.AreaId) + table.AddRow("ID", utils.PtrString(networkArea.AreaId)) table.AddSeparator() - table.AddRow("NAME", *networkArea.Name) + table.AddRow("NAME", utils.PtrString(networkArea.Name)) table.AddSeparator() - table.AddRow("STATE", *networkArea.State) + table.AddRow("STATE", utils.PtrString(networkArea.State)) table.AddSeparator() if len(networkRanges) > 0 { table.AddRow("NETWORK RANGES", strings.Join(networkRanges, ",")) @@ -174,31 +174,33 @@ func outputResult(p *print.Printer, outputFormat string, networkArea *iaas.Netwo table.AddRow(fmt.Sprintf("STATIC ROUTE %d", i+1), route) table.AddSeparator() } - if networkArea.Ipv4.TransferNetwork != nil { - table.AddRow("TRANSFER RANGE", *networkArea.Ipv4.TransferNetwork) - table.AddSeparator() - } - if networkArea.Ipv4.DefaultNameservers != nil { - table.AddRow("DNS NAME SERVERS", strings.Join(*networkArea.Ipv4.DefaultNameservers, ",")) - table.AddSeparator() - } - if networkArea.Ipv4.DefaultPrefixLen != nil { - table.AddRow("DEFAULT PREFIX LENGTH", *networkArea.Ipv4.DefaultPrefixLen) - table.AddSeparator() - } - if networkArea.Ipv4.MaxPrefixLen != nil { - table.AddRow("MAX PREFIX LENGTH", *networkArea.Ipv4.MaxPrefixLen) - table.AddSeparator() - } - if networkArea.Ipv4.MinPrefixLen != nil { - table.AddRow("MIN PREFIX LENGTH", *networkArea.Ipv4.MinPrefixLen) - table.AddSeparator() + if networkArea.Ipv4 != nil { + if networkArea.Ipv4.TransferNetwork != nil { + table.AddRow("TRANSFER RANGE", *networkArea.Ipv4.TransferNetwork) + table.AddSeparator() + } + if networkArea.Ipv4.DefaultNameservers != nil && len(*networkArea.Ipv4.DefaultNameservers) > 0 { + table.AddRow("DNS NAME SERVERS", strings.Join(*networkArea.Ipv4.DefaultNameservers, ",")) + table.AddSeparator() + } + if networkArea.Ipv4.DefaultPrefixLen != nil { + table.AddRow("DEFAULT PREFIX LENGTH", *networkArea.Ipv4.DefaultPrefixLen) + table.AddSeparator() + } + if networkArea.Ipv4.MaxPrefixLen != nil { + table.AddRow("MAX PREFIX LENGTH", *networkArea.Ipv4.MaxPrefixLen) + table.AddSeparator() + } + if networkArea.Ipv4.MinPrefixLen != nil { + table.AddRow("MIN PREFIX LENGTH", *networkArea.Ipv4.MinPrefixLen) + table.AddSeparator() + } } if len(attachedProjects) > 0 { table.AddRow("ATTACHED PROJECTS IDS", strings.Join(attachedProjects, "\n")) table.AddSeparator() } else { - table.AddRow("# ATTACHED PROJECTS", *networkArea.ProjectCount) + table.AddRow("# ATTACHED PROJECTS", utils.PtrString(networkArea.ProjectCount)) table.AddSeparator() } diff --git a/internal/cmd/beta/network-area/list/list.go b/internal/cmd/beta/network-area/list/list.go index 08b619851..984ebb4df 100644 --- a/internal/cmd/beta/network-area/list/list.go +++ b/internal/cmd/beta/network-area/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -16,9 +17,8 @@ import ( rmClient "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/client" rmUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" - - "github.com/spf13/cobra" ) const ( @@ -164,7 +164,20 @@ func outputResult(p *print.Printer, outputFormat string, networkAreas []iaas.Net table.SetHeader("ID", "Name", "Status", "Network Ranges", "# Attached Projects") for _, networkArea := range networkAreas { - table.AddRow(*networkArea.AreaId, *networkArea.Name, *networkArea.State, len(*networkArea.Ipv4.NetworkRanges), *networkArea.ProjectCount) + networkRanges := "n/a" + if ipv4 := networkArea.Ipv4; ipv4 != nil { + if netRange := ipv4.NetworkRanges; netRange != nil { + networkRanges = fmt.Sprint(len(*netRange)) + } + } + + table.AddRow( + utils.PtrString(networkArea.AreaId), + utils.PtrString(networkArea.Name), + utils.PtrString(networkArea.State), + networkRanges, + utils.PtrString(networkArea.ProjectCount), + ) table.AddSeparator() } diff --git a/internal/cmd/beta/network-area/network-range/create/create.go b/internal/cmd/beta/network-area/network-range/create/create.go index e66870dd4..4efb43d49 100644 --- a/internal/cmd/beta/network-area/network-range/create/create.go +++ b/internal/cmd/beta/network-area/network-range/create/create.go @@ -12,7 +12,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" + iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" "github.com/spf13/cobra" @@ -57,7 +58,7 @@ func NewCmd(p *print.Printer) *cobra.Command { } // Get network area label - networkAreaLabel, err := utils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId) + networkAreaLabel, err := iaasUtils.GetNetworkAreaName(ctx, apiClient, *model.OrganizationId, *model.NetworkAreaId) if err != nil { p.Debug(print.ErrorLevel, "get network area name: %v", err) networkAreaLabel = *model.NetworkAreaId @@ -82,7 +83,7 @@ func NewCmd(p *print.Printer) *cobra.Command { return fmt.Errorf("empty response from API") } - networkRange, err := utils.GetNetworkRangeFromAPIResponse(*model.NetworkRange, resp.Items) + networkRange, err := iaasUtils.GetNetworkRangeFromAPIResponse(*model.NetworkRange, resp.Items) if err != nil { return err } @@ -156,7 +157,7 @@ func outputResult(p *print.Printer, model *inputModel, networkAreaLabel string, return nil default: - p.Outputf("Created network range for SNA %q.\nNetwork range ID: %s\n", networkAreaLabel, *networkRange.NetworkRangeId) + p.Outputf("Created network range for SNA %q.\nNetwork range ID: %s\n", networkAreaLabel, utils.PtrString(networkRange.NetworkRangeId)) return nil } } diff --git a/internal/cmd/beta/network-area/network-range/describe/describe.go b/internal/cmd/beta/network-area/network-range/describe/describe.go index ed75127f9..8ca934686 100644 --- a/internal/cmd/beta/network-area/network-range/describe/describe.go +++ b/internal/cmd/beta/network-area/network-range/describe/describe.go @@ -128,9 +128,9 @@ func outputResult(p *print.Printer, outputFormat string, networkRange *iaas.Netw return nil default: table := tables.NewTable() - table.AddRow("ID", *networkRange.NetworkRangeId) + table.AddRow("ID", utils.PtrString(networkRange.NetworkRangeId)) table.AddSeparator() - table.AddRow("Network range", *networkRange.Prefix) + table.AddRow("Network range", utils.PtrString(networkRange.Prefix)) err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/network-area/route/create/create.go b/internal/cmd/beta/network-area/route/create/create.go index 24608f14f..a6f14b1c8 100644 --- a/internal/cmd/beta/network-area/route/create/create.go +++ b/internal/cmd/beta/network-area/route/create/create.go @@ -184,7 +184,7 @@ func outputResult(p *print.Printer, model *inputModel, networkAreaLabel string, return nil default: - p.Outputf("Created static route for SNA %q.\nStatic route ID: %s\n", networkAreaLabel, *route.RouteId) + p.Outputf("Created static route for SNA %q.\nStatic route ID: %s\n", networkAreaLabel, utils.PtrString(route.RouteId)) return nil } } diff --git a/internal/cmd/beta/network-area/route/describe/describe.go b/internal/cmd/beta/network-area/route/describe/describe.go index aa9dbb7c5..9a4c91300 100644 --- a/internal/cmd/beta/network-area/route/describe/describe.go +++ b/internal/cmd/beta/network-area/route/describe/describe.go @@ -133,11 +133,11 @@ func outputResult(p *print.Printer, outputFormat string, route *iaas.Route) erro return nil default: table := tables.NewTable() - table.AddRow("ID", *route.RouteId) + table.AddRow("ID", utils.PtrString(route.RouteId)) table.AddSeparator() - table.AddRow("PREFIX", *route.Prefix) + table.AddRow("PREFIX", utils.PtrString(route.Prefix)) table.AddSeparator() - table.AddRow("NEXTHOP", *route.Nexthop) + table.AddRow("NEXTHOP", utils.PtrString(route.Nexthop)) if route.Labels != nil && len(*route.Labels) > 0 { labels := []string{} for key, value := range *route.Labels { diff --git a/internal/cmd/beta/network-area/route/list/list.go b/internal/cmd/beta/network-area/route/list/list.go index 6a33d5e2f..6d5baa093 100644 --- a/internal/cmd/beta/network-area/route/list/list.go +++ b/internal/cmd/beta/network-area/route/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,9 +16,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" - - "github.com/spf13/cobra" ) const ( @@ -162,7 +162,11 @@ func outputResult(p *print.Printer, outputFormat string, routes []iaas.Route) er table.SetHeader("Static Route ID", "Next Hop", "Prefix") for _, route := range routes { - table.AddRow(*route.RouteId, *route.Nexthop, *route.Prefix) + table.AddRow( + utils.PtrString(route.RouteId), + utils.PtrString(route.Nexthop), + utils.PtrString(route.Prefix), + ) } p.Outputln(table.Render()) diff --git a/internal/cmd/beta/network-area/route/update/update.go b/internal/cmd/beta/network-area/route/update/update.go index bf11fc1a6..f022e0d2d 100644 --- a/internal/cmd/beta/network-area/route/update/update.go +++ b/internal/cmd/beta/network-area/route/update/update.go @@ -160,7 +160,7 @@ func outputResult(p *print.Printer, model *inputModel, networkAreaLabel string, return nil default: - p.Outputf("Updated static route for SNA %q.\nStatic route ID: %s\n", networkAreaLabel, *route.RouteId) + p.Outputf("Updated static route for SNA %q.\nStatic route ID: %s\n", networkAreaLabel, utils.PtrString(route.RouteId)) return nil } } diff --git a/internal/cmd/beta/network-interface/create/create.go b/internal/cmd/beta/network-interface/create/create.go index 0a1345f47..ac3686652 100644 --- a/internal/cmd/beta/network-interface/create/create.go +++ b/internal/cmd/beta/network-interface/create/create.go @@ -245,7 +245,7 @@ func outputResult(p *print.Printer, model *inputModel, nic *iaas.NIC) error { return nil default: - p.Outputf("Created network interface for project %q.\nNIC ID: %s\n", model.ProjectId, *nic.Id) + p.Outputf("Created network interface for project %q.\nNIC ID: %s\n", model.ProjectId, utils.PtrString(nic.Id)) return nil } } diff --git a/internal/cmd/beta/network-interface/describe/describe.go b/internal/cmd/beta/network-interface/describe/describe.go index 92da8a62d..02332642f 100644 --- a/internal/cmd/beta/network-interface/describe/describe.go +++ b/internal/cmd/beta/network-interface/describe/describe.go @@ -152,9 +152,9 @@ func outputResult(p *print.Printer, outputFormat string, nic *iaas.NIC) error { table.AddRow("IPV6", *nic.Ipv6) table.AddSeparator() } - table.AddRow("MAC", *nic.Mac) + table.AddRow("MAC", utils.PtrString(nic.Mac)) table.AddSeparator() - table.AddRow("NIC SECURITY", *nic.NicSecurity) + table.AddRow("NIC SECURITY", utils.PtrString(nic.NicSecurity)) if nic.AllowedAddresses != nil && len(*nic.AllowedAddresses) > 0 { allowedAddresses := []string{} for _, value := range *nic.AllowedAddresses { @@ -172,9 +172,9 @@ func outputResult(p *print.Printer, outputFormat string, nic *iaas.NIC) error { table.AddRow("LABELS", strings.Join(labels, "\n")) } table.AddSeparator() - table.AddRow("STATUS", *nic.Status) + table.AddRow("STATUS", utils.PtrString(nic.Status)) table.AddSeparator() - table.AddRow("TYPE", *nic.Type) + table.AddRow("TYPE", utils.PtrString(nic.Type)) if nic.SecurityGroups != nil && len(*nic.SecurityGroups) > 0 { table.AddSeparator() table.AddRow("SECURITY GROUPS", strings.Join(*nic.SecurityGroups, "\n")) diff --git a/internal/cmd/beta/network-interface/list/list.go b/internal/cmd/beta/network-interface/list/list.go index fc8b4a8c5..ec60bc980 100644 --- a/internal/cmd/beta/network-interface/list/list.go +++ b/internal/cmd/beta/network-interface/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,9 +15,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" - - "github.com/spf13/cobra" ) const ( @@ -168,11 +168,13 @@ func outputResult(p *print.Printer, outputFormat string, nics []iaas.NIC) error table.SetHeader("ID", "NAME", "NIC SECURITY", "STATUS", "TYPE") for _, nic := range nics { - name := "" - if nic.Name != nil { - name = *nic.Name - } - table.AddRow(*nic.Id, name, *nic.NicSecurity, *nic.Status, *nic.Type) + table.AddRow( + utils.PtrString(nic.Id), + utils.PtrString(nic.Name), + utils.PtrString(nic.NicSecurity), + utils.PtrString(nic.Status), + utils.PtrString(nic.Type), + ) table.AddSeparator() } diff --git a/internal/cmd/beta/network/describe/describe.go b/internal/cmd/beta/network/describe/describe.go index 31982a366..26efcc3dc 100644 --- a/internal/cmd/beta/network/describe/describe.go +++ b/internal/cmd/beta/network/describe/describe.go @@ -140,11 +140,11 @@ func outputResult(p *print.Printer, outputFormat string, network *iaas.Network) } table := tables.NewTable() - table.AddRow("ID", *network.NetworkId) + table.AddRow("ID", utils.PtrString(network.NetworkId)) table.AddSeparator() - table.AddRow("NAME", *network.Name) + table.AddRow("NAME", utils.PtrString(network.Name)) table.AddSeparator() - table.AddRow("STATE", *network.State) + table.AddRow("STATE", utils.PtrString(network.State)) table.AddSeparator() if network.PublicIp != nil { diff --git a/internal/cmd/beta/network/list/list.go b/internal/cmd/beta/network/list/list.go index ee388765c..62ca68e6f 100644 --- a/internal/cmd/beta/network/list/list.go +++ b/internal/cmd/beta/network/list/list.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "strings" "github.com/goccy/go-yaml" "github.com/stackitcloud/stackit-cli/internal/pkg/args" @@ -16,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" "github.com/spf13/cobra" @@ -164,12 +164,16 @@ func outputResult(p *print.Printer, outputFormat string, networks []iaas.Network if network.Routed != nil { routed = *network.Routed } - prefixes := "" - if network.Prefixes != nil && len(*network.Prefixes) > 0 { - prefixes = strings.Join(*network.Prefixes, ", ") - } - - table.AddRow(*network.NetworkId, *network.Name, *network.State, publicIp, prefixes, routed) + prefixes := utils.JoinStringPtr(network.Prefixes, ", ") + + table.AddRow( + utils.PtrString(network.NetworkId), + utils.PtrString(network.Name), + utils.PtrString(network.State), + publicIp, + prefixes, + routed, + ) table.AddSeparator() } diff --git a/internal/cmd/beta/public-ip/associate/associate.go b/internal/cmd/beta/public-ip/associate/associate.go index 7233b827c..1c33b2b8d 100644 --- a/internal/cmd/beta/public-ip/associate/associate.go +++ b/internal/cmd/beta/public-ip/associate/associate.go @@ -76,7 +76,7 @@ func NewCmd(p *print.Printer) *cobra.Command { return fmt.Errorf("associate public IP: %w", err) } - p.Outputf("Associated public IP %q with resource %v.\n", publicIpLabel, *resp.GetNetworkInterface()) + p.Outputf("Associated public IP %q with resource %v.\n", publicIpLabel, utils.PtrString(resp.GetNetworkInterface())) return nil }, } diff --git a/internal/cmd/beta/public-ip/create/create.go b/internal/cmd/beta/public-ip/create/create.go index 1f2bbe18c..dd1db3e5f 100644 --- a/internal/cmd/beta/public-ip/create/create.go +++ b/internal/cmd/beta/public-ip/create/create.go @@ -159,7 +159,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, publ return nil default: - p.Outputf("Created public IP for project %q.\nPublic IP ID: %s\n", projectLabel, *publicIp.Id) + p.Outputf("Created public IP for project %q.\nPublic IP ID: %s\n", projectLabel, utils.PtrString(publicIp.Id)) return nil } } diff --git a/internal/cmd/beta/public-ip/describe/describe.go b/internal/cmd/beta/public-ip/describe/describe.go index fe85c6902..19d03a4c9 100644 --- a/internal/cmd/beta/public-ip/describe/describe.go +++ b/internal/cmd/beta/public-ip/describe/describe.go @@ -121,9 +121,9 @@ func outputResult(p *print.Printer, outputFormat string, publicIp *iaas.PublicIp return nil default: table := tables.NewTable() - table.AddRow("ID", *publicIp.Id) + table.AddRow("ID", utils.PtrString(publicIp.Id)) table.AddSeparator() - table.AddRow("IP ADDRESS", *publicIp.Ip) + table.AddRow("IP ADDRESS", utils.PtrString(publicIp.Ip)) table.AddSeparator() if publicIp.NetworkInterface != nil { diff --git a/internal/cmd/beta/public-ip/list/list.go b/internal/cmd/beta/public-ip/list/list.go index 4ab82d197..2ac5b56ba 100644 --- a/internal/cmd/beta/public-ip/list/list.go +++ b/internal/cmd/beta/public-ip/list/list.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" "github.com/spf13/cobra" @@ -167,11 +168,12 @@ func outputResult(p *print.Printer, outputFormat string, publicIps []iaas.Public table.SetHeader("ID", "IP ADDRESS", "USED BY") for _, publicIp := range publicIps { - networkInterfaceId := "" - if publicIp.NetworkInterface != nil { - networkInterfaceId = *publicIp.GetNetworkInterface() - } - table.AddRow(*publicIp.Id, *publicIp.Ip, networkInterfaceId) + networkInterfaceId := utils.PtrStringDefault(publicIp.GetNetworkInterface(), "") + table.AddRow( + utils.PtrString(publicIp.Id), + utils.PtrString(publicIp.Ip), + networkInterfaceId, + ) table.AddSeparator() } diff --git a/internal/cmd/beta/security-group/rule/create/create.go b/internal/cmd/beta/security-group/rule/create/create.go index 04b49745e..2dcd875b6 100644 --- a/internal/cmd/beta/security-group/rule/create/create.go +++ b/internal/cmd/beta/security-group/rule/create/create.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" "github.com/spf13/cobra" @@ -240,7 +241,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel, securityGro if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s security group rule for security group %q in project %q.\nSecurity group rule ID: %s\n", operationState, securityGroupName, projectLabel, *securityGroupRule.Id) + p.Outputf("%s security group rule for security group %q in project %q.\nSecurity group rule ID: %s\n", operationState, securityGroupName, projectLabel, utils.PtrString(securityGroupRule.Id)) return nil } } diff --git a/internal/cmd/beta/security-group/rule/describe/describe.go b/internal/cmd/beta/security-group/rule/describe/describe.go index bc1b7abd3..64ff2834d 100644 --- a/internal/cmd/beta/security-group/rule/describe/describe.go +++ b/internal/cmd/beta/security-group/rule/describe/describe.go @@ -132,7 +132,7 @@ func outputResult(p *print.Printer, outputFormat string, securityGroupRule *iaas return nil default: table := tables.NewTable() - table.AddRow("ID", *securityGroupRule.Id) + table.AddRow("ID", utils.PtrString(securityGroupRule.Id)) table.AddSeparator() if securityGroupRule.Protocol != nil { @@ -147,7 +147,7 @@ func outputResult(p *print.Printer, outputFormat string, securityGroupRule *iaas } } - table.AddRow("DIRECTION", *securityGroupRule.Direction) + table.AddRow("DIRECTION", utils.PtrString(securityGroupRule.Direction)) table.AddSeparator() if securityGroupRule.PortRange != nil { diff --git a/internal/cmd/beta/security-group/rule/list/list.go b/internal/cmd/beta/security-group/rule/list/list.go index 55b75e8c2..385b98dd8 100644 --- a/internal/cmd/beta/security-group/rule/list/list.go +++ b/internal/cmd/beta/security-group/rule/list/list.go @@ -170,10 +170,7 @@ func outputResult(p *print.Printer, outputFormat string, securityGroupRules []ia table.SetHeader("ID", "ETHER TYPE", "DIRECTION", "PROTOCOL", "REMOTE SECURITY GROUP ID") for _, securityGroupRule := range securityGroupRules { - etherType := "" - if securityGroupRule.Ethertype != nil { - etherType = *securityGroupRule.Ethertype - } + etherType := utils.PtrStringDefault(securityGroupRule.Ethertype, "") protocolName := "" if securityGroupRule.Protocol != nil { diff --git a/internal/cmd/beta/server/backup/create/create.go b/internal/cmd/beta/server/backup/create/create.go index 90b3109c4..2ae95c259 100644 --- a/internal/cmd/beta/server/backup/create/create.go +++ b/internal/cmd/beta/server/backup/create/create.go @@ -13,6 +13,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverbackup/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" @@ -158,7 +159,7 @@ func outputResult(p *print.Printer, model *inputModel, resp *serverbackup.Backup return nil default: - p.Outputf("Triggered creation of server backup for server %s. Backup ID: %s\n", model.ServerId, *resp.Id) + p.Outputf("Triggered creation of server backup for server %s. Backup ID: %s\n", model.ServerId, utils.PtrString(resp.Id)) return nil } } diff --git a/internal/cmd/beta/server/backup/describe/describe.go b/internal/cmd/beta/server/backup/describe/describe.go index 38509fb97..a14f7a64d 100644 --- a/internal/cmd/beta/server/backup/describe/describe.go +++ b/internal/cmd/beta/server/backup/describe/describe.go @@ -129,23 +129,20 @@ func outputResult(p *print.Printer, outputFormat string, backup *serverbackup.Ba return nil default: table := tables.NewTable() - table.AddRow("ID", *backup.Id) + table.AddRow("ID", utils.PtrString(backup.Id)) table.AddSeparator() - table.AddRow("NAME", *backup.Name) + table.AddRow("NAME", utils.PtrString(backup.Name)) table.AddSeparator() - table.AddRow("SIZE (GB)", *backup.Size) + table.AddRow("SIZE (GB)", utils.PtrString(backup.Size)) table.AddSeparator() - table.AddRow("STATUS", *backup.Status) + table.AddRow("STATUS", utils.PtrString(backup.Status)) table.AddSeparator() - table.AddRow("CREATED AT", *backup.CreatedAt) + table.AddRow("CREATED AT", utils.PtrString(backup.CreatedAt)) table.AddSeparator() - table.AddRow("EXPIRES AT", *backup.ExpireAt) + table.AddRow("EXPIRES AT", utils.PtrString(backup.ExpireAt)) table.AddSeparator() - lastRestored := "" - if backup.LastRestoredAt != nil { - lastRestored = *backup.LastRestoredAt - } + lastRestored := utils.PtrStringDefault(backup.LastRestoredAt, "") table.AddRow("LAST RESTORED AT", lastRestored) table.AddSeparator() table.AddRow("VOLUME BACKUPS", len(*backup.VolumeBackups)) diff --git a/internal/cmd/beta/server/backup/list/list.go b/internal/cmd/beta/server/backup/list/list.go index 6588cd96e..f5c2dbf0e 100644 --- a/internal/cmd/beta/server/backup/list/list.go +++ b/internal/cmd/beta/server/backup/list/list.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" - + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverbackup/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" ) @@ -150,11 +149,17 @@ func outputResult(p *print.Printer, outputFormat string, backups []serverbackup. for i := range backups { s := backups[i] - lastRestored := "" - if s.LastRestoredAt != nil { - lastRestored = *s.LastRestoredAt - } - table.AddRow(*s.Id, *s.Name, *s.Size, *s.Status, *s.CreatedAt, *s.ExpireAt, lastRestored, len(*s.VolumeBackups)) + lastRestored := utils.PtrStringDefault(s.LastRestoredAt, "") + table.AddRow( + utils.PtrString(s.Id), + utils.PtrString(s.Name), + utils.PtrString(s.Size), + utils.PtrString(s.Status), + utils.PtrString(s.CreatedAt), + utils.PtrString(s.ExpireAt), + lastRestored, + len(*s.VolumeBackups), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/server/backup/schedule/create/create.go b/internal/cmd/beta/server/backup/schedule/create/create.go index d59a50df3..e35755d8e 100644 --- a/internal/cmd/beta/server/backup/schedule/create/create.go +++ b/internal/cmd/beta/server/backup/schedule/create/create.go @@ -13,6 +13,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverbackup/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" @@ -177,7 +178,7 @@ func outputResult(p *print.Printer, model *inputModel, resp *serverbackup.Backup return nil default: - p.Outputf("Created server backup schedule for server %s. Backup Schedule ID: %d\n", model.ServerId, *resp.Id) + p.Outputf("Created server backup schedule for server %s. Backup Schedule ID: %s\n", model.ServerId, utils.PtrString(resp.Id)) return nil } } diff --git a/internal/cmd/beta/server/backup/schedule/describe/describe.go b/internal/cmd/beta/server/backup/schedule/describe/describe.go index 27557b2c6..c94144658 100644 --- a/internal/cmd/beta/server/backup/schedule/describe/describe.go +++ b/internal/cmd/beta/server/backup/schedule/describe/describe.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "strings" "github.com/goccy/go-yaml" "github.com/stackitcloud/stackit-cli/internal/pkg/args" @@ -15,6 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverbackup/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" @@ -129,13 +129,13 @@ func outputResult(p *print.Printer, outputFormat string, schedule *serverbackup. return nil default: table := tables.NewTable() - table.AddRow("SCHEDULE ID", *schedule.Id) + table.AddRow("SCHEDULE ID", utils.PtrString(schedule.Id)) table.AddSeparator() - table.AddRow("SCHEDULE NAME", *schedule.Name) + table.AddRow("SCHEDULE NAME", utils.PtrString(schedule.Name)) table.AddSeparator() - table.AddRow("ENABLED", *schedule.Enabled) + table.AddRow("ENABLED", utils.PtrString(schedule.Enabled)) table.AddSeparator() - table.AddRow("RRULE", *schedule.Rrule) + table.AddRow("RRULE", utils.PtrString(schedule.Rrule)) table.AddSeparator() if schedule.BackupProperties != nil { table.AddRow("BACKUP NAME", *schedule.BackupProperties.Name) @@ -143,11 +143,7 @@ func outputResult(p *print.Printer, outputFormat string, schedule *serverbackup. table.AddRow("BACKUP RETENTION DAYS", *schedule.BackupProperties.RetentionPeriod) table.AddSeparator() ids := schedule.BackupProperties.VolumeIds - if ids == nil || len(*ids) == 0 { - table.AddRow("BACKUP VOLUME IDS", "") - } else { - table.AddRow("BACKUP VOLUME IDS", strings.Join(*ids, "\n")) - } + table.AddRow("BACKUP VOLUME IDS", utils.JoinStringPtr(ids, "\n")) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/server/backup/schedule/list/list.go b/internal/cmd/beta/server/backup/schedule/list/list.go index 0a5cd7f95..0709f81bd 100644 --- a/internal/cmd/beta/server/backup/schedule/list/list.go +++ b/internal/cmd/beta/server/backup/schedule/list/list.go @@ -4,10 +4,9 @@ import ( "context" "encoding/json" "fmt" - "strings" "github.com/goccy/go-yaml" - + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -16,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverbackup/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" ) @@ -151,11 +149,24 @@ func outputResult(p *print.Printer, outputFormat string, schedules []serverbacku for i := range schedules { s := schedules[i] + backupName := "" + retentionPeriod := "" ids := "" - if s.BackupProperties.VolumeIds != nil && len(*s.BackupProperties.VolumeIds) != 0 { - ids = strings.Join(*s.BackupProperties.VolumeIds, ",") + if s.BackupProperties != nil { + backupName = utils.PtrString(s.BackupProperties.Name) + retentionPeriod = utils.PtrString(s.BackupProperties.RetentionPeriod) + + ids = utils.JoinStringPtr(s.BackupProperties.VolumeIds, ",") } - table.AddRow(*s.Id, *s.Name, *s.Enabled, *s.Rrule, *s.BackupProperties.Name, *s.BackupProperties.RetentionPeriod, ids) + table.AddRow( + utils.PtrString(s.Id), + utils.PtrString(s.Name), + utils.PtrString(s.Enabled), + utils.PtrString(s.Rrule), + backupName, + retentionPeriod, + ids, + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/server/backup/schedule/update/update.go b/internal/cmd/beta/server/backup/schedule/update/update.go index 0d69981ea..88691fc82 100644 --- a/internal/cmd/beta/server/backup/schedule/update/update.go +++ b/internal/cmd/beta/server/backup/schedule/update/update.go @@ -13,6 +13,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverbackup/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" @@ -202,7 +203,7 @@ func outputResult(p *print.Printer, model *inputModel, resp *serverbackup.Backup return nil default: - p.Info("Updated server backup schedule %d\n", *resp.Id) + p.Info("Updated server backup schedule %s\n", utils.PtrString(resp.Id)) return nil } } diff --git a/internal/cmd/beta/server/command/create/create.go b/internal/cmd/beta/server/command/create/create.go index 6aeb808ec..15d3a0d40 100644 --- a/internal/cmd/beta/server/command/create/create.go +++ b/internal/cmd/beta/server/command/create/create.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/runcommand/client" runcommandUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/runcommand/utils" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/runcommand" ) @@ -156,7 +156,7 @@ func outputResult(p *print.Printer, model *inputModel, resp *runcommand.NewComma return nil default: - p.Outputf("Created server command for server %s. Command ID: %d\n", model.ServerId, *resp.Id) + p.Outputf("Created server command for server %s. Command ID: %s\n", model.ServerId, utils.PtrString(resp.Id)) return nil } } diff --git a/internal/cmd/beta/server/command/describe/describe.go b/internal/cmd/beta/server/command/describe/describe.go index 70db7e791..e7964c189 100644 --- a/internal/cmd/beta/server/command/describe/describe.go +++ b/internal/cmd/beta/server/command/describe/describe.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/runcommand/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/runcommand" ) @@ -128,23 +128,23 @@ func outputResult(p *print.Printer, outputFormat string, command *runcommand.Com return nil default: table := tables.NewTable() - table.AddRow("ID", *command.Id) + table.AddRow("ID", utils.PtrString(command.Id)) table.AddSeparator() - table.AddRow("COMMAND TEMPLATE NAME", *command.CommandTemplateName) + table.AddRow("COMMAND TEMPLATE NAME", utils.PtrString(command.CommandTemplateName)) table.AddSeparator() - table.AddRow("COMMAND TEMPLATE TITLE", *command.CommandTemplateTitle) + table.AddRow("COMMAND TEMPLATE TITLE", utils.PtrString(command.CommandTemplateTitle)) table.AddSeparator() - table.AddRow("STATUS", *command.Status) + table.AddRow("STATUS", utils.PtrString(command.Status)) table.AddSeparator() - table.AddRow("STARTED AT", *command.StartedAt) + table.AddRow("STARTED AT", utils.PtrString(command.StartedAt)) table.AddSeparator() - table.AddRow("FINISHED AT", *command.FinishedAt) + table.AddRow("FINISHED AT", utils.PtrString(command.FinishedAt)) table.AddSeparator() - table.AddRow("EXIT CODE", *command.ExitCode) + table.AddRow("EXIT CODE", utils.PtrString(command.ExitCode)) table.AddSeparator() - table.AddRow("COMMAND SCRIPT", *command.Script) + table.AddRow("COMMAND SCRIPT", utils.PtrString(command.Script)) table.AddSeparator() - table.AddRow("COMMAND OUTPUT", *command.Output) + table.AddRow("COMMAND OUTPUT", utils.PtrString(command.Output)) table.AddSeparator() err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/server/command/list/list.go b/internal/cmd/beta/server/command/list/list.go index b13a53319..5cdedac7d 100644 --- a/internal/cmd/beta/server/command/list/list.go +++ b/internal/cmd/beta/server/command/list/list.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" - + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/runcommand/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/runcommand" ) @@ -149,7 +148,14 @@ func outputResult(p *print.Printer, outputFormat string, commands []runcommand.C table.SetHeader("ID", "TEMPLATE NAME", "TEMPLATE TITLE", "STATUS", "STARTED_AT", "FINISHED_AT") for i := range commands { s := commands[i] - table.AddRow(*s.Id, *s.CommandTemplateName, *s.CommandTemplateTitle, *s.Status, *s.StartedAt, *s.FinishedAt) + table.AddRow( + utils.PtrString(s.Id), + utils.PtrString(s.CommandTemplateName), + utils.PtrString(s.CommandTemplateTitle), + utils.PtrString(s.Status), + utils.PtrString(s.StartedAt), + utils.PtrString(s.FinishedAt), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/server/command/template/describe/describe.go b/internal/cmd/beta/server/command/template/describe/describe.go index c393b1892..054e81940 100644 --- a/internal/cmd/beta/server/command/template/describe/describe.go +++ b/internal/cmd/beta/server/command/template/describe/describe.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/runcommand/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/runcommand" ) @@ -129,14 +129,16 @@ func outputResult(p *print.Printer, outputFormat string, commandTemplate *runcom return nil default: table := tables.NewTable() - table.AddRow("NAME", *commandTemplate.Name) + table.AddRow("NAME", utils.PtrString(commandTemplate.Name)) table.AddSeparator() - table.AddRow("TITLE", *commandTemplate.Title) + table.AddRow("TITLE", utils.PtrString(commandTemplate.Title)) table.AddSeparator() - table.AddRow("DESCRIPTION", *commandTemplate.Description) - table.AddSeparator() - table.AddRow("OS TYPE", strings.Join(*commandTemplate.OsType, "\n")) + table.AddRow("DESCRIPTION", utils.PtrString(commandTemplate.Description)) table.AddSeparator() + if commandTemplate.OsType != nil { + table.AddRow("OS TYPE", strings.Join(*commandTemplate.OsType, "\n")) + table.AddSeparator() + } if commandTemplate.ParameterSchema != nil { table.AddRow("PARAMS", *commandTemplate.ParameterSchema) } else { diff --git a/internal/cmd/beta/server/command/template/list/list.go b/internal/cmd/beta/server/command/template/list/list.go index a544b2fc6..03485da5a 100644 --- a/internal/cmd/beta/server/command/template/list/list.go +++ b/internal/cmd/beta/server/command/template/list/list.go @@ -4,10 +4,9 @@ import ( "context" "encoding/json" "fmt" - "strings" "github.com/goccy/go-yaml" - + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -16,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/runcommand/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/runcommand" ) @@ -143,7 +141,17 @@ func outputResult(p *print.Printer, outputFormat string, templates []runcommand. table.SetHeader("NAME", "OS TYPE", "TITLE") for i := range templates { s := templates[i] - table.AddRow(*s.Name, strings.Join(*s.OsType, ","), *s.Title) + + var osType string + if s.OsType != nil && len(*s.OsType) > 0 { + osType = utils.JoinStringPtr(s.OsType, ",") + } + + table.AddRow( + utils.PtrString(s.Name), + osType, + utils.PtrString(s.Title), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/server/console/console.go b/internal/cmd/beta/server/console/console.go index 1e9bf05e3..006936dcf 100644 --- a/internal/cmd/beta/server/console/console.go +++ b/internal/cmd/beta/server/console/console.go @@ -127,6 +127,9 @@ func outputResult(p *print.Printer, model *inputModel, serverLabel string, serve return nil default: + if serverUrl.GetUrl() == nil { + return fmt.Errorf("server url is nil") + } // unescape url in order to get rid of e.g. %40 unescapedURL, err := url.PathUnescape(*serverUrl.GetUrl()) if err != nil { diff --git a/internal/cmd/beta/server/create/create.go b/internal/cmd/beta/server/create/create.go index 106956633..f1c4bf0cf 100644 --- a/internal/cmd/beta/server/create/create.go +++ b/internal/cmd/beta/server/create/create.go @@ -353,7 +353,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, serv return nil default: - p.Outputf("Created server for project %q.\nServer ID: %s\n", projectLabel, *server.Id) + p.Outputf("Created server for project %q.\nServer ID: %s\n", projectLabel, utils.PtrString(server.Id)) return nil } } diff --git a/internal/cmd/beta/server/describe/describe.go b/internal/cmd/beta/server/describe/describe.go index abfe5a99b..0f69c92d6 100644 --- a/internal/cmd/beta/server/describe/describe.go +++ b/internal/cmd/beta/server/describe/describe.go @@ -129,19 +129,19 @@ func outputResult(p *print.Printer, model *inputModel, server *iaas.Server) erro table := tables.NewTable() table.SetTitle("Server") - table.AddRow("ID", *server.Id) + table.AddRow("ID", utils.PtrString(server.Id)) table.AddSeparator() - table.AddRow("NAME", *server.Name) + table.AddRow("NAME", utils.PtrString(server.Name)) table.AddSeparator() - table.AddRow("STATE", *server.Status) + table.AddRow("STATE", utils.PtrString(server.Status)) table.AddSeparator() - table.AddRow("AVAILABILITY ZONE", *server.AvailabilityZone) + table.AddRow("AVAILABILITY ZONE", utils.PtrString(server.AvailabilityZone)) table.AddSeparator() if server.BootVolume != nil && server.BootVolume.Id != nil { table.AddRow("BOOT VOLUME", *server.BootVolume.Id) table.AddSeparator() } - table.AddRow("POWER STATUS", *server.PowerStatus) + table.AddRow("POWER STATUS", utils.PtrString(server.PowerStatus)) table.AddSeparator() if server.AffinityGroup != nil { diff --git a/internal/cmd/beta/server/network-interface/attach/attach.go b/internal/cmd/beta/server/network-interface/attach/attach.go index 1a2b45d45..ecbf6bd41 100644 --- a/internal/cmd/beta/server/network-interface/attach/attach.go +++ b/internal/cmd/beta/server/network-interface/attach/attach.go @@ -14,6 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" ) @@ -106,7 +107,7 @@ func NewCmd(p *print.Printer) *cobra.Command { if err != nil { return fmt.Errorf("attach network interface: %w", err) } - p.Info("Attached network interface %q to server %q\n", *model.NicId, serverLabel) + p.Info("Attached network interface %q to server %q\n", utils.PtrString(model.NicId), serverLabel) return nil }, diff --git a/internal/cmd/beta/server/network-interface/detach/detach.go b/internal/cmd/beta/server/network-interface/detach/detach.go index fb11d12d9..57e9c1f7a 100644 --- a/internal/cmd/beta/server/network-interface/detach/detach.go +++ b/internal/cmd/beta/server/network-interface/detach/detach.go @@ -14,6 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" ) @@ -106,7 +107,7 @@ func NewCmd(p *print.Printer) *cobra.Command { if err != nil { return fmt.Errorf("detach network interface: %w", err) } - p.Info("Detached network interface %q from server %q\n", *model.NicId, serverLabel) + p.Info("Detached network interface %q from server %q\n", utils.PtrString(model.NicId), serverLabel) return nil }, diff --git a/internal/cmd/beta/server/network-interface/list/list.go b/internal/cmd/beta/server/network-interface/list/list.go index 307afdbcd..b715527f4 100644 --- a/internal/cmd/beta/server/network-interface/list/list.go +++ b/internal/cmd/beta/server/network-interface/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,9 +16,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" - - "github.com/spf13/cobra" ) const ( @@ -162,7 +162,7 @@ func outputResult(p *print.Printer, outputFormat, serverId string, serverNics [] for i := range serverNics { nic := serverNics[i] - table.AddRow(*nic.Id, serverId) + table.AddRow(utils.PtrString(nic.Id), serverId) } table.EnableAutoMergeOnColumns(2) diff --git a/internal/cmd/beta/server/os-update/create/create.go b/internal/cmd/beta/server/os-update/create/create.go index bf0bf664d..076a4d204 100644 --- a/internal/cmd/beta/server/os-update/create/create.go +++ b/internal/cmd/beta/server/os-update/create/create.go @@ -13,6 +13,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverosupdate/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" @@ -141,7 +142,7 @@ func outputResult(p *print.Printer, model *inputModel, resp *serverupdate.Update return nil default: - p.Outputf("Triggered creation of server os-update for server %s. Update ID: %d\n", model.ServerId, *resp.Id) + p.Outputf("Triggered creation of server os-update for server %s. Update ID: %s\n", model.ServerId, utils.PtrString(resp.Id)) return nil } } diff --git a/internal/cmd/beta/server/os-update/describe/describe.go b/internal/cmd/beta/server/os-update/describe/describe.go index 3a92dd3dc..2a3c1fbed 100644 --- a/internal/cmd/beta/server/os-update/describe/describe.go +++ b/internal/cmd/beta/server/os-update/describe/describe.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverosupdate/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) @@ -128,28 +128,19 @@ func outputResult(p *print.Printer, outputFormat string, update *serverupdate.Up return nil default: table := tables.NewTable() - table.AddRow("ID", *update.Id) + table.AddRow("ID", utils.PtrString(update.Id)) table.AddSeparator() - table.AddRow("STATUS", *update.Status) + table.AddRow("STATUS", utils.PtrString(update.Status)) table.AddSeparator() - if update.InstalledUpdates != nil { - table.AddRow("INSTALLED UPDATES", *update.InstalledUpdates) - } else { - table.AddRow("INSTALLED UPDATES", "...") - } + installedUpdates := utils.PtrStringDefault(update.InstalledUpdates, "n/a") + table.AddRow("INSTALLED UPDATES", installedUpdates) table.AddSeparator() - if update.FailedUpdates != nil { - table.AddRow("FAILED UPDATES", *update.FailedUpdates) - } else { - table.AddRow("FAILED UPDATES", "...") - } - table.AddRow("START DATE", *update.StartDate) + failedUpdates := utils.PtrStringDefault(update.FailedUpdates, "n/a") + table.AddRow("FAILED UPDATES", failedUpdates) + + table.AddRow("START DATE", utils.PtrString(update.StartDate)) table.AddSeparator() - if update.EndDate != nil { - table.AddRow("END DATE", *update.EndDate) - } else { - table.AddRow("END DATE", "...") - } + table.AddRow("END DATE", utils.PtrString(update.EndDate)) table.AddSeparator() err := table.Display(p) diff --git a/internal/cmd/beta/server/os-update/list/list.go b/internal/cmd/beta/server/os-update/list/list.go index 2f41b0ab1..5a25607dd 100644 --- a/internal/cmd/beta/server/os-update/list/list.go +++ b/internal/cmd/beta/server/os-update/list/list.go @@ -6,8 +6,6 @@ import ( "fmt" "strconv" - "github.com/goccy/go-yaml" - "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -16,7 +14,9 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverosupdate/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" + "github.com/goccy/go-yaml" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) @@ -151,22 +151,26 @@ func outputResult(p *print.Printer, outputFormat string, updates []serverupdate. for i := range updates { s := updates[i] - endDate := "..." - if s.EndDate != nil { - endDate = *s.EndDate - } + endDate := utils.PtrStringDefault(s.EndDate, "n/a") - installed := "..." + installed := "n/a" if s.InstalledUpdates != nil { installed = strconv.FormatInt(*s.InstalledUpdates, 10) } - failed := "..." + failed := "n/a" if s.FailedUpdates != nil { failed = strconv.FormatInt(*s.FailedUpdates, 10) } - table.AddRow(*s.Id, *s.Status, installed, failed, *s.StartDate, endDate) + table.AddRow( + utils.PtrString(s.Id), + utils.PtrString(s.Status), + installed, + failed, + utils.PtrString(s.StartDate), + endDate, + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/server/os-update/schedule/create/create.go b/internal/cmd/beta/server/os-update/schedule/create/create.go index 5a4d7ce93..fb767e690 100644 --- a/internal/cmd/beta/server/os-update/schedule/create/create.go +++ b/internal/cmd/beta/server/os-update/schedule/create/create.go @@ -13,6 +13,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverosupdate/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" @@ -161,7 +162,7 @@ func outputResult(p *print.Printer, model *inputModel, resp *serverupdate.Update return nil default: - p.Outputf("Created server os-update schedule for server %s. os-update Schedule ID: %d\n", model.ServerId, *resp.Id) + p.Outputf("Created server os-update schedule for server %s. os-update Schedule ID: %s\n", model.ServerId, utils.PtrString(resp.Id)) return nil } } diff --git a/internal/cmd/beta/server/os-update/schedule/describe/describe.go b/internal/cmd/beta/server/os-update/schedule/describe/describe.go index d46bf0a1e..33a5caefa 100644 --- a/internal/cmd/beta/server/os-update/schedule/describe/describe.go +++ b/internal/cmd/beta/server/os-update/schedule/describe/describe.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverosupdate/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) @@ -128,15 +128,15 @@ func outputResult(p *print.Printer, outputFormat string, schedule *serverupdate. return nil default: table := tables.NewTable() - table.AddRow("SCHEDULE ID", *schedule.Id) + table.AddRow("SCHEDULE ID", utils.PtrString(schedule.Id)) table.AddSeparator() - table.AddRow("SCHEDULE NAME", *schedule.Name) + table.AddRow("SCHEDULE NAME", utils.PtrString(schedule.Name)) table.AddSeparator() - table.AddRow("ENABLED", *schedule.Enabled) + table.AddRow("ENABLED", utils.PtrString(schedule.Enabled)) table.AddSeparator() - table.AddRow("RRULE", *schedule.Rrule) + table.AddRow("RRULE", utils.PtrString(schedule.Rrule)) table.AddSeparator() - table.AddRow("MAINTENANCE WINDOW", *schedule.MaintenanceWindow) + table.AddRow("MAINTENANCE WINDOW", utils.PtrString(schedule.MaintenanceWindow)) table.AddSeparator() err := table.Display(p) diff --git a/internal/cmd/beta/server/os-update/schedule/list/list.go b/internal/cmd/beta/server/os-update/schedule/list/list.go index f24d8becf..b9d1f0cff 100644 --- a/internal/cmd/beta/server/os-update/schedule/list/list.go +++ b/internal/cmd/beta/server/os-update/schedule/list/list.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" - + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverosupdate/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) @@ -149,7 +148,13 @@ func outputResult(p *print.Printer, outputFormat string, schedules []serverupdat table.SetHeader("SCHEDULE ID", "SCHEDULE NAME", "ENABLED", "RRULE", "MAINTENANCE WINDOW") for i := range schedules { s := schedules[i] - table.AddRow(*s.Id, *s.Name, *s.Enabled, *s.Rrule, *s.MaintenanceWindow) + table.AddRow( + utils.PtrString(s.Id), + utils.PtrString(s.Name), + utils.PtrString(s.Enabled), + utils.PtrString(s.Rrule), + utils.PtrString(s.MaintenanceWindow), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/server/os-update/schedule/update/update.go b/internal/cmd/beta/server/os-update/schedule/update/update.go index c85a429f2..5b8251d70 100644 --- a/internal/cmd/beta/server/os-update/schedule/update/update.go +++ b/internal/cmd/beta/server/os-update/schedule/update/update.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -13,8 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/serverosupdate/client" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/serverupdate" ) @@ -185,7 +185,7 @@ func outputResult(p *print.Printer, model *inputModel, resp *serverupdate.Update return nil default: - p.Info("Updated server os-update schedule %d\n", *resp.Id) + p.Info("Updated server os-update schedule %s\n", utils.PtrString(resp.Id)) return nil } } diff --git a/internal/cmd/beta/server/rescue/rescue.go b/internal/cmd/beta/server/rescue/rescue.go index b634587fe..ef6474220 100644 --- a/internal/cmd/beta/server/rescue/rescue.go +++ b/internal/cmd/beta/server/rescue/rescue.go @@ -93,7 +93,7 @@ func NewCmd(p *print.Printer) *cobra.Command { if model.Async { operationState = "Triggered rescue of" } - p.Info("%s server %q. Image %q is used as temporary boot image\n", operationState, serverLabel, *model.ImageId) + p.Info("%s server %q. Image %q is used as temporary boot image\n", operationState, serverLabel, utils.PtrString(model.ImageId)) return nil }, diff --git a/internal/cmd/beta/server/volume/describe/describe.go b/internal/cmd/beta/server/volume/describe/describe.go index d5e4a3146..cc77e843d 100644 --- a/internal/cmd/beta/server/volume/describe/describe.go +++ b/internal/cmd/beta/server/volume/describe/describe.go @@ -147,11 +147,11 @@ func outputResult(p *print.Printer, outputFormat, serverLabel, volumeLabel strin return nil default: table := tables.NewTable() - table.AddRow("SERVER ID", *volume.ServerId) + table.AddRow("SERVER ID", utils.PtrString(volume.ServerId)) table.AddSeparator() table.AddRow("SERVER NAME", serverLabel) table.AddSeparator() - table.AddRow("VOLUME ID", *volume.VolumeId) + table.AddRow("VOLUME ID", utils.PtrString(volume.VolumeId)) table.AddSeparator() // check if name is set if volumeLabel != "" { diff --git a/internal/cmd/beta/server/volume/list/list.go b/internal/cmd/beta/server/volume/list/list.go index f09ddf5dc..eefc47f94 100644 --- a/internal/cmd/beta/server/volume/list/list.go +++ b/internal/cmd/beta/server/volume/list/list.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" - + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -16,9 +16,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" iaasUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" - - "github.com/spf13/cobra" ) const ( @@ -150,7 +149,7 @@ func outputResult(p *print.Printer, outputFormat, serverLabel string, volumeName table.SetHeader("SERVER ID", "SERVER NAME", "VOLUME ID", "VOLUME NAME") for i := range volumes { s := volumes[i] - table.AddRow(*s.ServerId, serverLabel, *s.VolumeId, volumeNames[i]) + table.AddRow(utils.PtrString(s.ServerId), serverLabel, utils.PtrString(s.VolumeId), volumeNames[i]) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/sqlserverflex/database/describe/describe.go b/internal/cmd/beta/sqlserverflex/database/describe/describe.go index 26f5babc4..009ebfc0c 100644 --- a/internal/cmd/beta/sqlserverflex/database/describe/describe.go +++ b/internal/cmd/beta/sqlserverflex/database/describe/describe.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,9 +15,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/sqlserverflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex" - - "github.com/spf13/cobra" ) const ( @@ -130,9 +130,9 @@ func outputResult(p *print.Printer, outputFormat string, database *sqlserverflex default: database := database.Database table := tables.NewTable() - table.AddRow("ID", *database.Id) + table.AddRow("ID", utils.PtrString(database.Id)) table.AddSeparator() - table.AddRow("NAME", *database.Name) + table.AddRow("NAME", utils.PtrString(database.Name)) table.AddSeparator() if database.Options != nil { if database.Options.CompatibilityLevel != nil { diff --git a/internal/cmd/beta/sqlserverflex/database/list/list.go b/internal/cmd/beta/sqlserverflex/database/list/list.go index 990884253..aac09fc65 100644 --- a/internal/cmd/beta/sqlserverflex/database/list/list.go +++ b/internal/cmd/beta/sqlserverflex/database/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,9 +16,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/sqlserverflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex" - - "github.com/spf13/cobra" ) const ( @@ -159,7 +159,7 @@ func outputResult(p *print.Printer, outputFormat string, databases []sqlserverfl table.SetHeader("ID", "NAME") for i := range databases { database := databases[i] - table.AddRow(*database.Id, *database.Name) + table.AddRow(utils.PtrString(database.Id), utils.PtrString(database.Name)) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/sqlserverflex/instance/create/create.go b/internal/cmd/beta/sqlserverflex/instance/create/create.go index 8e0b87819..82ec72f8b 100644 --- a/internal/cmd/beta/sqlserverflex/instance/create/create.go +++ b/internal/cmd/beta/sqlserverflex/instance/create/create.go @@ -284,7 +284,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, *resp.Id) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, utils.PtrString(resp.Id)) return nil } } diff --git a/internal/cmd/beta/sqlserverflex/instance/describe/describe.go b/internal/cmd/beta/sqlserverflex/instance/describe/describe.go index a9e868292..59525c85d 100644 --- a/internal/cmd/beta/sqlserverflex/instance/describe/describe.go +++ b/internal/cmd/beta/sqlserverflex/instance/describe/describe.go @@ -117,29 +117,32 @@ func outputResult(p *print.Printer, outputFormat string, instance *sqlserverflex return nil default: - aclsArray := *instance.Acl.Items - acls := strings.Join(aclsArray, ",") + var acls string + if instance.Acl != nil && instance.Acl.HasItems() { + aclsArray := *instance.Acl.Items + acls = strings.Join(aclsArray, ",") + } table := tables.NewTable() - table.AddRow("ID", *instance.Id) + table.AddRow("ID", utils.PtrString(instance.Id)) table.AddSeparator() - table.AddRow("NAME", *instance.Name) + table.AddRow("NAME", utils.PtrString(instance.Name)) table.AddSeparator() - table.AddRow("STATUS", *instance.Status) + table.AddRow("STATUS", utils.PtrString(instance.Status)) table.AddSeparator() - table.AddRow("STORAGE SIZE (GB)", *instance.Storage.Size) + table.AddRow("STORAGE SIZE (GB)", utils.PtrString(instance.Storage.Size)) table.AddSeparator() - table.AddRow("VERSION", *instance.Version) + table.AddRow("VERSION", utils.PtrString(instance.Version)) table.AddSeparator() - table.AddRow("BACKUP SCHEDULE (UTC)", *instance.BackupSchedule) + table.AddRow("BACKUP SCHEDULE (UTC)", utils.PtrString(instance.BackupSchedule)) table.AddSeparator() table.AddRow("ACL", acls) table.AddSeparator() - table.AddRow("FLAVOR DESCRIPTION", *instance.Flavor.Description) + table.AddRow("FLAVOR DESCRIPTION", utils.PtrString(instance.Flavor.Description)) table.AddSeparator() - table.AddRow("CPU", *instance.Flavor.Cpu) + table.AddRow("CPU", utils.PtrString(instance.Flavor.Cpu)) table.AddSeparator() - table.AddRow("RAM (GB)", *instance.Flavor.Memory) + table.AddRow("RAM (GB)", utils.PtrString(instance.Flavor.Memory)) table.AddSeparator() err := table.Display(p) diff --git a/internal/cmd/beta/sqlserverflex/instance/list/list.go b/internal/cmd/beta/sqlserverflex/instance/list/list.go index 92814d3e4..b524c088a 100644 --- a/internal/cmd/beta/sqlserverflex/instance/list/list.go +++ b/internal/cmd/beta/sqlserverflex/instance/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/sqlserverflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex" ) @@ -152,7 +152,11 @@ func outputResult(p *print.Printer, outputFormat string, instances []sqlserverfl table.SetHeader("ID", "NAME", "STATUS") for i := range instances { instance := instances[i] - table.AddRow(*instance.Id, *instance.Name, *instance.Status) + table.AddRow( + utils.PtrString(instance.Id), + utils.PtrString(instance.Name), + utils.PtrString(instance.Status), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/sqlserverflex/user/create/create.go b/internal/cmd/beta/sqlserverflex/user/create/create.go index 7fc9b05e0..7153f4dca 100644 --- a/internal/cmd/beta/sqlserverflex/user/create/create.go +++ b/internal/cmd/beta/sqlserverflex/user/create/create.go @@ -16,6 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/sqlserverflex/client" sqlserverflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/sqlserverflex/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex" ) @@ -161,9 +162,9 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, use return nil default: - p.Outputf("Created user for instance %q. User ID: %s\n\n", instanceLabel, *user.Id) - p.Outputf("Username: %s\n", *user.Username) - p.Outputf("Password: %s\n", *user.Password) + p.Outputf("Created user for instance %q. User ID: %s\n\n", instanceLabel, utils.PtrString(user.Id)) + p.Outputf("Username: %s\n", utils.PtrString(user.Username)) + p.Outputf("Password: %s\n", utils.PtrString(user.Password)) if user.Roles != nil && len(*user.Roles) != 0 { p.Outputf("Roles: [%v]\n", strings.Join(*user.Roles, ", ")) } diff --git a/internal/cmd/beta/sqlserverflex/user/describe/describe.go b/internal/cmd/beta/sqlserverflex/user/describe/describe.go index 0f0e28ae5..a679a3e05 100644 --- a/internal/cmd/beta/sqlserverflex/user/describe/describe.go +++ b/internal/cmd/beta/sqlserverflex/user/describe/describe.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/sqlserverflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex" @@ -137,9 +138,9 @@ func outputResult(p *print.Printer, outputFormat string, user sqlserverflex.User return nil default: table := tables.NewTable() - table.AddRow("ID", *user.Id) + table.AddRow("ID", utils.PtrString(user.Id)) table.AddSeparator() - table.AddRow("USERNAME", *user.Username) + table.AddRow("USERNAME", utils.PtrString(user.Username)) if user.Roles != nil && len(*user.Roles) != 0 { table.AddSeparator() table.AddRow("ROLES", strings.Join(*user.Roles, "\n")) diff --git a/internal/cmd/beta/sqlserverflex/user/list/list.go b/internal/cmd/beta/sqlserverflex/user/list/list.go index 005f437f9..32f9d1557 100644 --- a/internal/cmd/beta/sqlserverflex/user/list/list.go +++ b/internal/cmd/beta/sqlserverflex/user/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/sqlserverflex/client" sqlserverflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/sqlserverflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex" ) @@ -160,7 +160,10 @@ func outputResult(p *print.Printer, outputFormat string, users []sqlserverflex.I table.SetHeader("ID", "USERNAME") for i := range users { user := users[i] - table.AddRow(*user.Id, *user.Username) + table.AddRow( + utils.PtrString(user.Id), + utils.PtrString(user.Username), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/beta/sqlserverflex/user/reset-password/reset_password.go b/internal/cmd/beta/sqlserverflex/user/reset-password/reset_password.go index d8cd47ad4..6218406a6 100644 --- a/internal/cmd/beta/sqlserverflex/user/reset-password/reset_password.go +++ b/internal/cmd/beta/sqlserverflex/user/reset-password/reset_password.go @@ -14,6 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/sqlserverflex/client" sqlserverflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/sqlserverflex/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex" @@ -152,8 +153,8 @@ func outputResult(p *print.Printer, model *inputModel, userLabel, instanceLabel return nil default: p.Outputf("Reset password for user %q of instance %q\n\n", userLabel, instanceLabel) - p.Outputf("Username: %s\n", *user.Username) - p.Outputf("New password: %s\n", *user.Password) + p.Outputf("Username: %s\n", utils.PtrString(user.Username)) + p.Outputf("New password: %s\n", utils.PtrString(user.Password)) if user.Uri != nil && *user.Uri != "" { p.Outputf("New URI: %s\n", *user.Uri) } diff --git a/internal/cmd/beta/volume/create/create.go b/internal/cmd/beta/volume/create/create.go index 943ee7d85..0374c5f46 100644 --- a/internal/cmd/beta/volume/create/create.go +++ b/internal/cmd/beta/volume/create/create.go @@ -217,7 +217,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, volu return nil default: - p.Outputf("Created volume for project %q.\nVolume ID: %s\n", projectLabel, *volume.Id) + p.Outputf("Created volume for project %q.\nVolume ID: %s\n", projectLabel, utils.PtrString(volume.Id)) return nil } } diff --git a/internal/cmd/beta/volume/describe/describe.go b/internal/cmd/beta/volume/describe/describe.go index 3f70f6fea..c62a0cedf 100644 --- a/internal/cmd/beta/volume/describe/describe.go +++ b/internal/cmd/beta/volume/describe/describe.go @@ -121,17 +121,17 @@ func outputResult(p *print.Printer, outputFormat string, volume *iaas.Volume) er return nil default: table := tables.NewTable() - table.AddRow("ID", *volume.Id) + table.AddRow("ID", utils.PtrString(volume.Id)) table.AddSeparator() - table.AddRow("NAME", *volume.Name) + table.AddRow("NAME", utils.PtrString(volume.Name)) table.AddSeparator() - table.AddRow("STATE", *volume.Status) + table.AddRow("STATE", utils.PtrString(volume.Status)) table.AddSeparator() - table.AddRow("VOLUME SIZE (GB)", *volume.Size) + table.AddRow("VOLUME SIZE (GB)", utils.PtrString(volume.Size)) table.AddSeparator() - table.AddRow("PERFORMANCE CLASS", *volume.PerformanceClass) + table.AddRow("PERFORMANCE CLASS", utils.PtrString(volume.PerformanceClass)) table.AddSeparator() - table.AddRow("AVAILABILITY ZONE", *volume.AvailabilityZone) + table.AddRow("AVAILABILITY ZONE", utils.PtrString(volume.AvailabilityZone)) table.AddSeparator() if volume.Source != nil { diff --git a/internal/cmd/beta/volume/list/list.go b/internal/cmd/beta/volume/list/list.go index 47b73170b..a9920f438 100644 --- a/internal/cmd/beta/volume/list/list.go +++ b/internal/cmd/beta/volume/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,9 +16,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" - - "github.com/spf13/cobra" ) const ( @@ -167,11 +167,14 @@ func outputResult(p *print.Printer, outputFormat string, volumes []iaas.Volume) table.SetHeader("ID", "Name", "Status", "Server", "Availability Zone", "Size (GB)") for _, volume := range volumes { - serverId := "" - if volume.ServerId != nil { - serverId = *volume.ServerId - } - table.AddRow(*volume.Id, *volume.Name, *volume.Status, serverId, *volume.AvailabilityZone, *volume.Size) + table.AddRow( + utils.PtrString(volume.Id), + utils.PtrString(volume.Name), + utils.PtrString(volume.Status), + utils.PtrString(volume.ServerId), + utils.PtrString(volume.AvailabilityZone), + utils.PtrString(volume.Size), + ) table.AddSeparator() } diff --git a/internal/cmd/beta/volume/performance-class/describe/describe.go b/internal/cmd/beta/volume/performance-class/describe/describe.go index 4864f25c5..b867f2e70 100644 --- a/internal/cmd/beta/volume/performance-class/describe/describe.go +++ b/internal/cmd/beta/volume/performance-class/describe/describe.go @@ -121,7 +121,7 @@ func outputResult(p *print.Printer, outputFormat string, performanceClass *iaas. return nil default: table := tables.NewTable() - table.AddRow("NAME", *performanceClass.Name) + table.AddRow("NAME", utils.PtrString(performanceClass.Name)) table.AddSeparator() table.AddRow("DESCRIPTION", utils.PtrString(performanceClass.Description)) table.AddSeparator() diff --git a/internal/cmd/beta/volume/performance-class/list/list.go b/internal/cmd/beta/volume/performance-class/list/list.go index 7c37b7284..3bc6ed37f 100644 --- a/internal/cmd/beta/volume/performance-class/list/list.go +++ b/internal/cmd/beta/volume/performance-class/list/list.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/iaas/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" "github.com/spf13/cobra" @@ -167,7 +168,7 @@ func outputResult(p *print.Printer, outputFormat string, performanceClasses []ia table.SetHeader("Name", "Description") for _, performanceClass := range performanceClasses { - table.AddRow(*performanceClass.Name, *performanceClass.Description) + table.AddRow(utils.PtrString(performanceClass.Name), utils.PtrString(performanceClass.Description)) table.AddSeparator() } diff --git a/internal/cmd/dns/record-set/create/create.go b/internal/cmd/dns/record-set/create/create.go index ed77e5735..3ed23f57d 100644 --- a/internal/cmd/dns/record-set/create/create.go +++ b/internal/cmd/dns/record-set/create/create.go @@ -203,7 +203,7 @@ func outputResult(p *print.Printer, model *inputModel, zoneLabel string, resp *d if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s record set for zone %s. Record set ID: %s\n", operationState, zoneLabel, *resp.Rrset.Id) + p.Outputf("%s record set for zone %s. Record set ID: %s\n", operationState, zoneLabel, utils.PtrString(resp.Rrset.Id)) return nil } } diff --git a/internal/cmd/dns/record-set/describe/describe.go b/internal/cmd/dns/record-set/describe/describe.go index 221729d91..536ff5c64 100644 --- a/internal/cmd/dns/record-set/describe/describe.go +++ b/internal/cmd/dns/record-set/describe/describe.go @@ -139,15 +139,15 @@ func outputResult(p *print.Printer, outputFormat string, recordSet *dns.RecordSe recordsDataJoin := strings.Join(recordsData, ", ") table := tables.NewTable() - table.AddRow("ID", *recordSet.Id) + table.AddRow("ID", utils.PtrString(recordSet.Id)) table.AddSeparator() - table.AddRow("NAME", *recordSet.Name) + table.AddRow("NAME", utils.PtrString(recordSet.Name)) table.AddSeparator() - table.AddRow("STATE", *recordSet.State) + table.AddRow("STATE", utils.PtrString(recordSet.State)) table.AddSeparator() - table.AddRow("TTL", *recordSet.Ttl) + table.AddRow("TTL", utils.PtrString(recordSet.Ttl)) table.AddSeparator() - table.AddRow("TYPE", *recordSet.Type) + table.AddRow("TYPE", utils.PtrString(recordSet.Type)) table.AddSeparator() table.AddRow("RECORDS DATA", recordsDataJoin) err := table.Display(p) diff --git a/internal/cmd/dns/record-set/list/list.go b/internal/cmd/dns/record-set/list/list.go index caca06264..3e2bf0f81 100644 --- a/internal/cmd/dns/record-set/list/list.go +++ b/internal/cmd/dns/record-set/list/list.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -17,8 +18,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" dnsUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/dns" ) @@ -276,7 +276,14 @@ func outputResult(p *print.Printer, outputFormat string, recordSets []dns.Record recordData = append(recordData, *r.Content) } recordDataJoin := strings.Join(recordData, ", ") - table.AddRow(*rs.Id, *rs.Name, *rs.State, *rs.Ttl, *rs.Type, recordDataJoin) + table.AddRow( + utils.PtrString(rs.Id), + utils.PtrString(rs.Name), + utils.PtrString(rs.State), + utils.PtrString(rs.Ttl), + utils.PtrString(rs.Type), + recordDataJoin, + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/dns/zone/clone/clone.go b/internal/cmd/dns/zone/clone/clone.go index e1af7022a..e950cdcce 100644 --- a/internal/cmd/dns/zone/clone/clone.go +++ b/internal/cmd/dns/zone/clone/clone.go @@ -182,7 +182,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp if model.Async { operationState = "Triggered cloning of" } - p.Outputf("%s zone for project %q. Zone ID: %s\n", operationState, projectLabel, *resp.Zone.Id) + p.Outputf("%s zone for project %q. Zone ID: %s\n", operationState, projectLabel, utils.PtrString(resp.Zone.Id)) return nil } } diff --git a/internal/cmd/dns/zone/create/create.go b/internal/cmd/dns/zone/create/create.go index 32e6ab636..2ad572f5a 100644 --- a/internal/cmd/dns/zone/create/create.go +++ b/internal/cmd/dns/zone/create/create.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/dns" @@ -218,7 +219,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s zone for project %q. Zone ID: %s\n", operationState, projectLabel, *resp.Zone.Id) + p.Outputf("%s zone for project %q. Zone ID: %s\n", operationState, projectLabel, utils.PtrString(resp.Zone.Id)) return nil } } diff --git a/internal/cmd/dns/zone/describe/describe.go b/internal/cmd/dns/zone/describe/describe.go index 578dee03c..56308972f 100644 --- a/internal/cmd/dns/zone/describe/describe.go +++ b/internal/cmd/dns/zone/describe/describe.go @@ -118,35 +118,35 @@ func outputResult(p *print.Printer, outputFormat string, zone *dns.Zone) error { return nil default: table := tables.NewTable() - table.AddRow("ID", *zone.Id) + table.AddRow("ID", utils.PtrString(zone.Id)) table.AddSeparator() - table.AddRow("NAME", *zone.Name) + table.AddRow("NAME", utils.PtrString(zone.Name)) table.AddSeparator() - table.AddRow("DESCRIPTION", *zone.Description) + table.AddRow("DESCRIPTION", utils.PtrString(zone.Description)) table.AddSeparator() - table.AddRow("STATE", *zone.State) + table.AddRow("STATE", utils.PtrString(zone.State)) table.AddSeparator() - table.AddRow("TYPE", *zone.Type) + table.AddRow("TYPE", utils.PtrString(zone.Type)) table.AddSeparator() - table.AddRow("DNS NAME", *zone.DnsName) + table.AddRow("DNS NAME", utils.PtrString(zone.DnsName)) table.AddSeparator() - table.AddRow("REVERSE ZONE", *zone.IsReverseZone) + table.AddRow("REVERSE ZONE", utils.PtrString(zone.IsReverseZone)) table.AddSeparator() - table.AddRow("RECORD COUNT", *zone.RecordCount) + table.AddRow("RECORD COUNT", utils.PtrString(zone.RecordCount)) table.AddSeparator() - table.AddRow("CONTACT EMAIL", *zone.ContactEmail) + table.AddRow("CONTACT EMAIL", utils.PtrString(zone.ContactEmail)) table.AddSeparator() - table.AddRow("DEFAULT TTL", *zone.DefaultTTL) + table.AddRow("DEFAULT TTL", utils.PtrString(zone.DefaultTTL)) table.AddSeparator() - table.AddRow("SERIAL NUMBER", *zone.SerialNumber) + table.AddRow("SERIAL NUMBER", utils.PtrString(zone.SerialNumber)) table.AddSeparator() - table.AddRow("REFRESH TIME", *zone.RefreshTime) + table.AddRow("REFRESH TIME", utils.PtrString(zone.RefreshTime)) table.AddSeparator() - table.AddRow("RETRY TIME", *zone.RetryTime) + table.AddRow("RETRY TIME", utils.PtrString(zone.RetryTime)) table.AddSeparator() - table.AddRow("EXPIRE TIME", *zone.ExpireTime) + table.AddRow("EXPIRE TIME", utils.PtrString(zone.ExpireTime)) table.AddSeparator() - table.AddRow("NEGATIVE CACHE", *zone.NegativeCache) + table.AddRow("NEGATIVE CACHE", utils.PtrString(zone.NegativeCache)) err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) diff --git a/internal/cmd/dns/zone/list/list.go b/internal/cmd/dns/zone/list/list.go index a318ef381..7f1bd2a34 100644 --- a/internal/cmd/dns/zone/list/list.go +++ b/internal/cmd/dns/zone/list/list.go @@ -17,6 +17,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/dns" @@ -260,7 +261,13 @@ func outputResult(p *print.Printer, outputFormat string, zones []dns.Zone) error table.SetHeader("ID", "NAME", "STATE", "TYPE", "DNS NAME", "RECORD COUNT") for i := range zones { z := zones[i] - table.AddRow(*z.Id, *z.Name, *z.State, *z.Type, *z.DnsName, *z.RecordCount) + table.AddRow(utils.PtrString(z.Id), + utils.PtrString(z.Name), + utils.PtrString(z.State), + utils.PtrString(z.Type), + utils.PtrString(z.DnsName), + utils.PtrString(z.RecordCount), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/load-balancer/create/create.go b/internal/cmd/load-balancer/create/create.go index c6364ef2e..e106d4aa9 100644 --- a/internal/cmd/load-balancer/create/create.go +++ b/internal/cmd/load-balancer/create/create.go @@ -6,20 +6,18 @@ import ( "fmt" "github.com/google/uuid" - - "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" - "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" - + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" + "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/load-balancer/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" + "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/wait" ) @@ -108,7 +106,7 @@ func NewCmd(p *print.Printer) *cobra.Command { if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s load balancer with name %q \n", operationState, *model.Payload.Name) + p.Outputf("%s load balancer with name %q \n", operationState, utils.PtrString(model.Payload.Name)) return nil }, } diff --git a/internal/cmd/load-balancer/describe/describe.go b/internal/cmd/load-balancer/describe/describe.go index d08e5a99e..bd98be64c 100644 --- a/internal/cmd/load-balancer/describe/describe.go +++ b/internal/cmd/load-balancer/describe/describe.go @@ -14,6 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/load-balancer/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" @@ -160,10 +161,7 @@ func buildLoadBalancerTable(loadBalancer *loadbalancer.LoadBalancer) tables.Tabl networkId = *networks[0].NetworkId } - externalAdress := "-" - if loadBalancer.ExternalAddress != nil { - externalAdress = *loadBalancer.ExternalAddress - } + externalAddress := utils.PtrStringDefault(loadBalancer.ExternalAddress, "-") errorDescriptions := []string{} if loadBalancer.Errors != nil && len((*loadBalancer.Errors)) > 0 { @@ -174,9 +172,9 @@ func buildLoadBalancerTable(loadBalancer *loadbalancer.LoadBalancer) tables.Tabl table := tables.NewTable() table.SetTitle("Load Balancer") - table.AddRow("NAME", *loadBalancer.Name) + table.AddRow("NAME", utils.PtrString(loadBalancer.Name)) table.AddSeparator() - table.AddRow("STATE", *loadBalancer.Status) + table.AddRow("STATE", utils.PtrString(loadBalancer.Status)) table.AddSeparator() if len(errorDescriptions) > 0 { table.AddRow("ERROR DESCRIPTIONS", strings.Join(errorDescriptions, "\n")) @@ -184,7 +182,7 @@ func buildLoadBalancerTable(loadBalancer *loadbalancer.LoadBalancer) tables.Tabl } table.AddRow("PRIVATE ACCESS ONLY", privateAccessOnly) table.AddSeparator() - table.AddRow("ATTACHED PUBLIC IP", externalAdress) + table.AddRow("ATTACHED PUBLIC IP", externalAddress) table.AddSeparator() table.AddRow("ATTACHED NETWORK ID", networkId) table.AddSeparator() @@ -198,7 +196,12 @@ func buildListenersTable(listeners []loadbalancer.Listener) tables.Table { table.SetHeader("NAME", "PORT", "PROTOCOL", "TARGET POOL") for i := range listeners { listener := listeners[i] - table.AddRow(*listener.Name, *listener.Port, *listener.Protocol, *listener.TargetPool) + table.AddRow( + utils.PtrString(listener.Name), + utils.PtrString(listener.Port), + utils.PtrString(listener.Protocol), + utils.PtrString(listener.TargetPool), + ) } return table } @@ -208,7 +211,7 @@ func buildTargetPoolsTable(targetPools []loadbalancer.TargetPool) tables.Table { table.SetTitle("Target Pools") table.SetHeader("NAME", "PORT", "TARGETS") for _, targetPool := range targetPools { - table.AddRow(*targetPool.Name, *targetPool.TargetPort, len(*targetPool.Targets)) + table.AddRow(utils.PtrString(targetPool.Name), utils.PtrString(targetPool.TargetPort), len(*targetPool.Targets)) } return table } diff --git a/internal/cmd/load-balancer/list/list.go b/internal/cmd/load-balancer/list/list.go index 512f984db..dde4f20ec 100644 --- a/internal/cmd/load-balancer/list/list.go +++ b/internal/cmd/load-balancer/list/list.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/load-balancer/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" @@ -153,11 +154,14 @@ func outputResult(p *print.Printer, outputFormat string, loadBalancers []loadbal table.SetHeader("NAME", "STATE", "IP ADDRESS", "LISTENERS", "TARGET POOLS") for i := range loadBalancers { l := loadBalancers[i] - externalAdress := "-" - if l.ExternalAddress != nil { - externalAdress = *l.ExternalAddress - } - table.AddRow(*l.Name, *l.Status, externalAdress, len(*l.Listeners), len(*l.TargetPools)) + externalAdress := utils.PtrStringDefault(l.ExternalAddress, "-") + table.AddRow( + utils.PtrString(l.Name), + utils.PtrString(l.Status), + externalAdress, + len(*l.Listeners), + len(*l.TargetPools), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/load-balancer/observability-credentials/add/add.go b/internal/cmd/load-balancer/observability-credentials/add/add.go index b6421195a..26c09bb90 100644 --- a/internal/cmd/load-balancer/observability-credentials/add/add.go +++ b/internal/cmd/load-balancer/observability-credentials/add/add.go @@ -167,7 +167,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp return nil default: - p.Outputf("Added Load Balancer observability credentials on project %q. Credentials reference: %q\n", projectLabel, *resp.Credential.CredentialsRef) + p.Outputf("Added Load Balancer observability credentials on project %q. Credentials reference: %q\n", projectLabel, utils.PtrString(resp.Credential.CredentialsRef)) return nil } } diff --git a/internal/cmd/load-balancer/observability-credentials/describe/describe.go b/internal/cmd/load-balancer/observability-credentials/describe/describe.go index 27d27caf8..2fd1bc6e3 100644 --- a/internal/cmd/load-balancer/observability-credentials/describe/describe.go +++ b/internal/cmd/load-balancer/observability-credentials/describe/describe.go @@ -13,6 +13,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/load-balancer/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" @@ -113,12 +114,17 @@ func outputResult(p *print.Printer, outputFormat string, credentials *loadbalanc return nil default: + if credentials == nil || credentials.Credential == nil { + p.Info("No credentials found") + return nil + } + table := tables.NewTable() - table.AddRow("REFERENCE", *credentials.Credential.CredentialsRef) + table.AddRow("REFERENCE", utils.PtrString(credentials.Credential.CredentialsRef)) table.AddSeparator() - table.AddRow("DISPLAY NAME", *credentials.Credential.DisplayName) + table.AddRow("DISPLAY NAME", utils.PtrString(credentials.Credential.DisplayName)) table.AddSeparator() - table.AddRow("USERNAME", *credentials.Credential.Username) + table.AddRow("USERNAME", utils.PtrString(credentials.Credential.Username)) table.AddSeparator() err := table.Display(p) if err != nil { diff --git a/internal/cmd/load-balancer/observability-credentials/list/list.go b/internal/cmd/load-balancer/observability-credentials/list/list.go index 11c1a0161..8ed74da16 100644 --- a/internal/cmd/load-balancer/observability-credentials/list/list.go +++ b/internal/cmd/load-balancer/observability-credentials/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,10 +15,9 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/load-balancer/client" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/load-balancer/utils" + lbUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/load-balancer/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" ) @@ -92,7 +92,7 @@ func NewCmd(p *print.Printer) *cobra.Command { if err != nil { return err } - credentials, err = utils.FilterCredentials(ctx, apiClient, credentials, model.ProjectId, filterOp) + credentials, err = lbUtils.FilterCredentials(ctx, apiClient, credentials, model.ProjectId, filterOp) if err != nil { return fmt.Errorf("filter credentials: %w", err) } @@ -189,7 +189,7 @@ func outputResult(p *print.Printer, outputFormat string, credentials []loadbalan table.SetHeader("REFERENCE", "DISPLAY NAME", "USERNAME") for i := range credentials { c := credentials[i] - table.AddRow(*c.CredentialsRef, *c.DisplayName, *c.Username) + table.AddRow(utils.PtrString(c.CredentialsRef), utils.PtrString(c.DisplayName), utils.PtrString(c.Username)) } err := table.Display(p) if err != nil { @@ -207,12 +207,12 @@ func getFilterOp(used, unused bool) (int, error) { } if !used && !unused { - return utils.OP_FILTER_NOP, nil + return lbUtils.OP_FILTER_NOP, nil } if used { - return utils.OP_FILTER_USED, nil + return lbUtils.OP_FILTER_USED, nil } - return utils.OP_FILTER_UNUSED, nil + return lbUtils.OP_FILTER_UNUSED, nil } diff --git a/internal/cmd/load-balancer/target-pool/describe/describe.go b/internal/cmd/load-balancer/target-pool/describe/describe.go index e3e5921fc..8eeceef88 100644 --- a/internal/cmd/load-balancer/target-pool/describe/describe.go +++ b/internal/cmd/load-balancer/target-pool/describe/describe.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,10 +16,9 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/load-balancer/client" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/load-balancer/utils" + lbUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/load-balancer/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer" ) @@ -67,12 +67,12 @@ func NewCmd(p *print.Printer) *cobra.Command { return fmt.Errorf("read load balancer: %w", err) } - targetPool := utils.FindLoadBalancerTargetPoolByName(*resp.TargetPools, model.TargetPoolName) + targetPool := lbUtils.FindLoadBalancerTargetPoolByName(*resp.TargetPools, model.TargetPoolName) if targetPool == nil { return fmt.Errorf("target pool not found") } - listener := utils.FindLoadBalancerListenerByTargetPool(*resp.Listeners, *targetPool.Name) + listener := lbUtils.FindLoadBalancerListenerByTargetPool(*resp.Listeners, *targetPool.Name) return outputResult(p, model.OutputFormat, *targetPool, listener) }, @@ -183,7 +183,11 @@ func outputResultAsTable(p *print.Printer, targetPool loadbalancer.TargetPool, l listenerStr := "-" if listener != nil { - listenerStr = fmt.Sprintf("%s (Port:%d, Protocol: %s)", *listener.Name, *listener.Port, *listener.Protocol) + listenerStr = fmt.Sprintf("%s (Port:%s, Protocol: %s)", + utils.PtrString(listener.Name), + utils.PtrString(listener.Port), + utils.PtrString(listener.Protocol), + ) } table := tables.NewTable() diff --git a/internal/cmd/logme/credentials/create/create.go b/internal/cmd/logme/credentials/create/create.go index 5d67574a2..b21bed0f0 100644 --- a/internal/cmd/logme/credentials/create/create.go +++ b/internal/cmd/logme/credentials/create/create.go @@ -144,20 +144,21 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res return nil default: - p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) + p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, utils.PtrString(resp.Id)) // The username field cannot be set by the user so we only display it if it's not returned empty - username := *resp.Raw.Credentials.Username - if username != "" { - p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) - } - if !model.ShowPassword { - p.Outputf("Password: \n") - } else { - p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) + if resp.HasRaw() && resp.Raw.Credentials != nil { + if username := resp.Raw.Credentials.Username; username != nil && *username != "" { + p.Outputf("Username: %s\n", utils.PtrString(username)) + } + if !model.ShowPassword { + p.Outputf("Password: \n") + } else { + p.Outputf("Password: %s\n", utils.PtrString(resp.Raw.Credentials.Password)) + } + p.Outputf("Host: %s\n", utils.PtrString(resp.Raw.Credentials.Host)) + p.Outputf("Port: %s\n", utils.PtrString(resp.Raw.Credentials.Port)) } - p.Outputf("Host: %s\n", *resp.Raw.Credentials.Host) - p.Outputf("Port: %d\n", *resp.Raw.Credentials.Port) - p.Outputf("URI: %s\n", *resp.Uri) + p.Outputf("URI: %s\n", utils.PtrString(resp.Uri)) return nil } } diff --git a/internal/cmd/logme/credentials/describe/describe.go b/internal/cmd/logme/credentials/describe/describe.go index e2b7551a9..2d51fe40b 100644 --- a/internal/cmd/logme/credentials/describe/describe.go +++ b/internal/cmd/logme/credentials/describe/describe.go @@ -131,17 +131,20 @@ func outputResult(p *print.Printer, outputFormat string, credentials *logme.Cred return nil default: table := tables.NewTable() - table.AddRow("ID", *credentials.Id) + table.AddRow("ID", utils.PtrString(credentials.Id)) table.AddSeparator() // The username field cannot be set by the user so we only display it if it's not returned empty - username := *credentials.Raw.Credentials.Username - if username != "" { - table.AddRow("USERNAME", *credentials.Raw.Credentials.Username) - table.AddSeparator() + if raw := credentials.Raw; raw != nil { + if cred := raw.Credentials; cred != nil { + if username := cred.Username; username != nil && *username != "" { + table.AddRow("USERNAME", *username) + table.AddSeparator() + } + table.AddRow("PASSWORD", utils.PtrString(cred.Password)) + table.AddSeparator() + table.AddRow("URI", utils.PtrString(cred.Uri)) + } } - table.AddRow("PASSWORD", *credentials.Raw.Credentials.Password) - table.AddSeparator() - table.AddRow("URI", *credentials.Raw.Credentials.Uri) err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) diff --git a/internal/cmd/logme/credentials/list/list.go b/internal/cmd/logme/credentials/list/list.go index e53a61174..cac18139b 100644 --- a/internal/cmd/logme/credentials/list/list.go +++ b/internal/cmd/logme/credentials/list/list.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" logmeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/logme" @@ -157,7 +158,7 @@ func outputResult(p *print.Printer, outputFormat string, credentials []logme.Cre table.SetHeader("ID") for i := range credentials { c := credentials[i] - table.AddRow(*c.Id) + table.AddRow(utils.PtrString(c.Id)) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/logme/instance/create/create.go b/internal/cmd/logme/instance/create/create.go index c6b34b62c..d77f9f64e 100644 --- a/internal/cmd/logme/instance/create/create.go +++ b/internal/cmd/logme/instance/create/create.go @@ -274,7 +274,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, *resp.InstanceId) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, utils.PtrString(resp.InstanceId)) return nil } } diff --git a/internal/cmd/logme/instance/describe/describe.go b/internal/cmd/logme/instance/describe/describe.go index 9e477f16a..896f42982 100644 --- a/internal/cmd/logme/instance/describe/describe.go +++ b/internal/cmd/logme/instance/describe/describe.go @@ -119,15 +119,15 @@ func outputResult(p *print.Printer, outputFormat string, instance *logme.Instanc return nil default: table := tables.NewTable() - table.AddRow("ID", *instance.InstanceId) + table.AddRow("ID", utils.PtrString(instance.InstanceId)) table.AddSeparator() - table.AddRow("NAME", *instance.Name) + table.AddRow("NAME", utils.PtrString(instance.Name)) table.AddSeparator() - table.AddRow("LAST OPERATION TYPE", *instance.LastOperation.Type) + table.AddRow("LAST OPERATION TYPE", utils.PtrString(instance.LastOperation.Type)) table.AddSeparator() - table.AddRow("LAST OPERATION STATE", *instance.LastOperation.State) + table.AddRow("LAST OPERATION STATE", utils.PtrString(instance.LastOperation.State)) table.AddSeparator() - table.AddRow("PLAN ID", *instance.PlanId) + table.AddRow("PLAN ID", utils.PtrString(instance.PlanId)) // Only show ACL if it's present and not empty acl := (*instance.Parameters)[aclParameterKey] aclStr, ok := acl.(string) diff --git a/internal/cmd/logme/instance/list/list.go b/internal/cmd/logme/instance/list/list.go index dba438103..e8784d054 100644 --- a/internal/cmd/logme/instance/list/list.go +++ b/internal/cmd/logme/instance/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/logme" ) @@ -152,7 +152,12 @@ func outputResult(p *print.Printer, outputFormat string, instances []logme.Insta table.SetHeader("ID", "NAME", "LAST OPERATION TYPE", "LAST OPERATION STATE") for i := range instances { instance := instances[i] - table.AddRow(*instance.InstanceId, *instance.Name, *instance.LastOperation.Type, *instance.LastOperation.State) + table.AddRow( + utils.PtrString(instance.InstanceId), + utils.PtrString(instance.Name), + utils.PtrString(instance.LastOperation.Type), + utils.PtrString(instance.LastOperation.State), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/logme/plans/plans.go b/internal/cmd/logme/plans/plans.go index b1500eccd..6177a4143 100644 --- a/internal/cmd/logme/plans/plans.go +++ b/internal/cmd/logme/plans/plans.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/logme" ) @@ -154,7 +154,13 @@ func outputResult(p *print.Printer, outputFormat string, plans []logme.Offering) o := plans[i] for j := range *o.Plans { p := (*o.Plans)[j] - table.AddRow(*o.Name, *o.Version, *p.Id, *p.Name, *p.Description) + table.AddRow( + utils.PtrString(o.Name), + utils.PtrString(o.Version), + utils.PtrString(p.Id), + utils.PtrString(p.Name), + utils.PtrString(p.Description), + ) } table.AddSeparator() } diff --git a/internal/cmd/mariadb/credentials/create/create.go b/internal/cmd/mariadb/credentials/create/create.go index 602286821..404d5e8a9 100644 --- a/internal/cmd/mariadb/credentials/create/create.go +++ b/internal/cmd/mariadb/credentials/create/create.go @@ -145,20 +145,21 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res return nil default: - p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) + p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, utils.PtrString(resp.Id)) // The username field cannot be set by the user, so we only display it if it's not returned empty - username := *resp.Raw.Credentials.Username - if username != "" { - p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) - } - if !model.ShowPassword { - p.Outputf("Password: \n") - } else { - p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) + if resp.HasRaw() && resp.Raw.Credentials != nil { + if username := resp.Raw.Credentials.Username; username != nil && *username != "" { + p.Outputf("Username: %s\n", *username) + } + if !model.ShowPassword { + p.Outputf("Password: \n") + } else { + p.Outputf("Password: %s\n", utils.PtrString(resp.Raw.Credentials.Password)) + } + p.Outputf("Host: %s\n", utils.PtrString(resp.Raw.Credentials.Host)) + p.Outputf("Port: %s\n", utils.PtrString(resp.Raw.Credentials.Port)) } - p.Outputf("Host: %s\n", *resp.Raw.Credentials.Host) - p.Outputf("Port: %d\n", *resp.Raw.Credentials.Port) - p.Outputf("URI: %s\n", *resp.Uri) + p.Outputf("URI: %s\n", utils.PtrString(resp.Uri)) return nil } } diff --git a/internal/cmd/mariadb/credentials/describe/describe.go b/internal/cmd/mariadb/credentials/describe/describe.go index ae5eeece0..31a09a17e 100644 --- a/internal/cmd/mariadb/credentials/describe/describe.go +++ b/internal/cmd/mariadb/credentials/describe/describe.go @@ -134,14 +134,15 @@ func outputResult(p *print.Printer, outputFormat string, credentials *mariadb.Cr table.AddRow("ID", *credentials.Id) table.AddSeparator() // The username field cannot be set by the user so we only display it if it's not returned empty - username := *credentials.Raw.Credentials.Username - if username != "" { - table.AddRow("USERNAME", *credentials.Raw.Credentials.Username) + if credentials.HasRaw() && credentials.Raw.Credentials != nil { + if username := credentials.Raw.Credentials.Username; username != nil && *username != "" { + table.AddRow("USERNAME", *username) + table.AddSeparator() + } + table.AddRow("PASSWORD", utils.PtrString(credentials.Raw.Credentials.Password)) table.AddSeparator() + table.AddRow("URI", utils.PtrString(credentials.Raw.Credentials.Uri)) } - table.AddRow("PASSWORD", *credentials.Raw.Credentials.Password) - table.AddSeparator() - table.AddRow("URI", *credentials.Raw.Credentials.Uri) err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) diff --git a/internal/cmd/mariadb/credentials/list/list.go b/internal/cmd/mariadb/credentials/list/list.go index dde2678a1..47e15f379 100644 --- a/internal/cmd/mariadb/credentials/list/list.go +++ b/internal/cmd/mariadb/credentials/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" mariadbUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/mariadb" ) @@ -157,7 +157,7 @@ func outputResult(p *print.Printer, outputFormat string, credentials []mariadb.C table.SetHeader("ID") for i := range credentials { c := credentials[i] - table.AddRow(*c.Id) + table.AddRow(utils.PtrString(c.Id)) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/mariadb/instance/create/create.go b/internal/cmd/mariadb/instance/create/create.go index 097588efd..031ef8930 100644 --- a/internal/cmd/mariadb/instance/create/create.go +++ b/internal/cmd/mariadb/instance/create/create.go @@ -274,7 +274,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, *resp.InstanceId) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, utils.PtrString(resp.InstanceId)) return nil } } diff --git a/internal/cmd/mariadb/instance/describe/describe.go b/internal/cmd/mariadb/instance/describe/describe.go index 94323bc5e..49788795c 100644 --- a/internal/cmd/mariadb/instance/describe/describe.go +++ b/internal/cmd/mariadb/instance/describe/describe.go @@ -119,15 +119,15 @@ func outputResult(p *print.Printer, outputFormat string, instance *mariadb.Insta return nil default: table := tables.NewTable() - table.AddRow("ID", *instance.InstanceId) + table.AddRow("ID", utils.PtrString(instance.InstanceId)) table.AddSeparator() - table.AddRow("NAME", *instance.Name) + table.AddRow("NAME", utils.PtrString(instance.Name)) table.AddSeparator() - table.AddRow("LAST OPERATION TYPE", *instance.LastOperation.Type) + table.AddRow("LAST OPERATION TYPE", utils.PtrString(instance.LastOperation.Type)) table.AddSeparator() - table.AddRow("LAST OPERATION STATE", *instance.LastOperation.State) + table.AddRow("LAST OPERATION STATE", utils.PtrString(instance.LastOperation.State)) table.AddSeparator() - table.AddRow("PLAN ID", *instance.PlanId) + table.AddRow("PLAN ID", utils.PtrString(instance.PlanId)) // Only show ACL if it's present and not empty acl := (*instance.Parameters)[aclParameterKey] aclStr, ok := acl.(string) diff --git a/internal/cmd/mariadb/instance/list/list.go b/internal/cmd/mariadb/instance/list/list.go index e550b01f4..f360462d3 100644 --- a/internal/cmd/mariadb/instance/list/list.go +++ b/internal/cmd/mariadb/instance/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/mariadb" ) @@ -152,7 +152,12 @@ func outputResult(p *print.Printer, outputFormat string, instances []mariadb.Ins table.SetHeader("ID", "NAME", "LAST OPERATION TYPE", "LAST OPERATION STATE") for i := range instances { instance := instances[i] - table.AddRow(*instance.InstanceId, *instance.Name, *instance.LastOperation.Type, *instance.LastOperation.State) + table.AddRow( + utils.PtrString(instance.InstanceId), + utils.PtrString(instance.Name), + utils.PtrString(instance.LastOperation.Type), + utils.PtrString(instance.LastOperation.State), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/mariadb/plans/plans.go b/internal/cmd/mariadb/plans/plans.go index fff09aaba..6d6053c21 100644 --- a/internal/cmd/mariadb/plans/plans.go +++ b/internal/cmd/mariadb/plans/plans.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/mariadb" ) @@ -154,7 +154,13 @@ func outputResult(p *print.Printer, outputFormat string, plans []mariadb.Offerin o := plans[i] for j := range *o.Plans { plan := (*o.Plans)[j] - table.AddRow(*o.Name, *o.Version, *plan.Id, *plan.Name, *plan.Description) + table.AddRow( + utils.PtrString(o.Name), + utils.PtrString(o.Version), + utils.PtrString(plan.Id), + utils.PtrString(plan.Name), + utils.PtrString(plan.Description), + ) } table.AddSeparator() } diff --git a/internal/cmd/mongodbflex/backup/describe/describe.go b/internal/cmd/mongodbflex/backup/describe/describe.go index 6488c6ee7..4d2d9d108 100644 --- a/internal/cmd/mongodbflex/backup/describe/describe.go +++ b/internal/cmd/mongodbflex/backup/describe/describe.go @@ -6,7 +6,6 @@ import ( "fmt" "github.com/goccy/go-yaml" - "github.com/inhies/go-bytesize" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -15,8 +14,9 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" + mongoUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" ) @@ -60,7 +60,7 @@ func NewCmd(p *print.Printer) *cobra.Command { return err } - instanceLabel, err := utils.GetInstanceName(ctx, apiClient, model.ProjectId, model.InstanceId) + instanceLabel, err := mongoUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.InstanceId) if err != nil { p.Debug(print.ErrorLevel, "get instance name: %v", err) instanceLabel = model.InstanceId @@ -79,7 +79,7 @@ func NewCmd(p *print.Printer) *cobra.Command { return fmt.Errorf("get restore jobs for MongoDB Flex instance %q: %w", instanceLabel, err) } - restoreJobState := utils.GetRestoreStatus(model.BackupId, restoreJobs) + restoreJobState := mongoUtils.GetRestoreStatus(model.BackupId, restoreJobs) return outputResult(p, cmd, model.OutputFormat, restoreJobState, *resp.Item) }, } @@ -145,13 +145,14 @@ func outputResult(p *print.Printer, cmd *cobra.Command, outputFormat, restoreSta return nil default: table := tables.NewTable() - table.AddRow("ID", *backup.Id) + table.AddRow("ID", utils.PtrString(backup.Id)) table.AddSeparator() - table.AddRow("CREATED AT", *backup.StartTime) + table.AddRow("CREATED AT", utils.PtrString(backup.StartTime)) table.AddSeparator() - table.AddRow("EXPIRES AT", *backup.EndTime) + table.AddRow("EXPIRES AT", utils.PtrString(backup.EndTime)) table.AddSeparator() - table.AddRow("BACKUP SIZE", bytesize.New(float64(*backup.Size))) + backupSize := utils.PtrByteSizeDefault(backup.Size, "n/a") + table.AddRow("BACKUP SIZE", backupSize) table.AddSeparator() table.AddRow("RESTORE STATUS", restoreStatus) diff --git a/internal/cmd/mongodbflex/backup/list/list.go b/internal/cmd/mongodbflex/backup/list/list.go index 13002dc49..9f19d9c3c 100644 --- a/internal/cmd/mongodbflex/backup/list/list.go +++ b/internal/cmd/mongodbflex/backup/list/list.go @@ -6,7 +6,6 @@ import ( "fmt" "github.com/goccy/go-yaml" - "github.com/inhies/go-bytesize" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -16,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" @@ -168,7 +168,13 @@ func outputResult(p *print.Printer, outputFormat string, backups []mongodbflex.B for i := range backups { backup := backups[i] restoreStatus := mongodbflexUtils.GetRestoreStatus(*backup.Id, restoreJobs) - table.AddRow(*backup.Id, *backup.StartTime, *backup.EndTime, bytesize.New(float64(*backup.Size)), restoreStatus) + backupSize := utils.PtrByteSizeDefault(backup.Size, "n/a") + table.AddRow( + utils.PtrString(backup.Id), + utils.PtrString(backup.StartTime), + utils.PtrString(backup.EndTime), + backupSize, + restoreStatus) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/mongodbflex/backup/restore-jobs/restore_jobs.go b/internal/cmd/mongodbflex/backup/restore-jobs/restore_jobs.go index 6b289d2f8..e77538fd3 100644 --- a/internal/cmd/mongodbflex/backup/restore-jobs/restore_jobs.go +++ b/internal/cmd/mongodbflex/backup/restore-jobs/restore_jobs.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" ) @@ -162,7 +162,13 @@ func outputResult(p *print.Printer, outputFormat string, restoreJobs []mongodbfl for i := range restoreJobs { restoreJob := restoreJobs[i] - table.AddRow(*restoreJob.Id, *restoreJob.BackupID, *restoreJob.InstanceId, *restoreJob.Date, *restoreJob.Status) + table.AddRow( + utils.PtrString(restoreJob.Id), + utils.PtrString(restoreJob.BackupID), + utils.PtrString(restoreJob.InstanceId), + utils.PtrString(restoreJob.Date), + utils.PtrString(restoreJob.Status), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/mongodbflex/backup/schedule/schedule.go b/internal/cmd/mongodbflex/backup/schedule/schedule.go index c8a5a316d..e4b0cbb75 100644 --- a/internal/cmd/mongodbflex/backup/schedule/schedule.go +++ b/internal/cmd/mongodbflex/backup/schedule/schedule.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" ) @@ -139,18 +139,20 @@ func outputResult(p *print.Printer, outputFormat string, instance *mongodbflex.I return nil default: table := tables.NewTable() - table.AddRow("BACKUP SCHEDULE (UTC)", *instance.BackupSchedule) - table.AddSeparator() - table.AddRow("DAILY SNAPSHOT RETENTION (DAYS)", (*instance.Options)["dailySnapshotRetentionDays"]) - table.AddSeparator() - table.AddRow("MONTHLY SNAPSHOT RETENTION (MONTHS)", (*instance.Options)["monthlySnapshotRetentionMonths"]) - table.AddSeparator() - table.AddRow("POINT IN TIME WINDOW (HOURS)", (*instance.Options)["pointInTimeWindowHours"]) - table.AddSeparator() - table.AddRow("SNAPSHOT RETENTION (DAYS)", (*instance.Options)["snapshotRetentionDays"]) - table.AddSeparator() - table.AddRow("WEEKLY SNAPSHOT RETENTION (WEEKS)", (*instance.Options)["weeklySnapshotRetentionWeeks"]) + table.AddRow("BACKUP SCHEDULE (UTC)", utils.PtrString(instance.BackupSchedule)) table.AddSeparator() + if instance.Options != nil { + table.AddRow("DAILY SNAPSHOT RETENTION (DAYS)", (*instance.Options)["dailySnapshotRetentionDays"]) + table.AddSeparator() + table.AddRow("MONTHLY SNAPSHOT RETENTION (MONTHS)", (*instance.Options)["monthlySnapshotRetentionMonths"]) + table.AddSeparator() + table.AddRow("POINT IN TIME WINDOW (HOURS)", (*instance.Options)["pointInTimeWindowHours"]) + table.AddSeparator() + table.AddRow("SNAPSHOT RETENTION (DAYS)", (*instance.Options)["snapshotRetentionDays"]) + table.AddSeparator() + table.AddRow("WEEKLY SNAPSHOT RETENTION (WEEKS)", (*instance.Options)["weeklySnapshotRetentionWeeks"]) + table.AddSeparator() + } err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) diff --git a/internal/cmd/mongodbflex/instance/create/create.go b/internal/cmd/mongodbflex/instance/create/create.go index 5962804a1..f4882ab95 100644 --- a/internal/cmd/mongodbflex/instance/create/create.go +++ b/internal/cmd/mongodbflex/instance/create/create.go @@ -296,7 +296,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, *resp.Id) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, utils.PtrString(resp.Id)) return nil } } diff --git a/internal/cmd/mongodbflex/instance/describe/describe.go b/internal/cmd/mongodbflex/instance/describe/describe.go index 810ae1a87..bac7b7205 100644 --- a/internal/cmd/mongodbflex/instance/describe/describe.go +++ b/internal/cmd/mongodbflex/instance/describe/describe.go @@ -140,17 +140,23 @@ func outputResult(p *print.Printer, outputFormat string, instance *mongodbflex.I table.AddSeparator() table.AddRow("ACL", acls) table.AddSeparator() - table.AddRow("FLAVOR DESCRIPTION", *instance.Flavor.Description) - table.AddSeparator() + if instance.HasFlavor() && instance.Flavor.HasDescription() { + table.AddRow("FLAVOR DESCRIPTION", *instance.Flavor.Description) + table.AddSeparator() + } table.AddRow("TYPE", instanceType) table.AddSeparator() - table.AddRow("REPLICAS", *instance.Replicas) - table.AddSeparator() - table.AddRow("CPU", *instance.Flavor.Cpu) - table.AddSeparator() - table.AddRow("RAM (GB)", *instance.Flavor.Memory) - table.AddSeparator() - table.AddRow("BACKUP SCHEDULE (UTC)", *instance.BackupSchedule) + if instance.HasReplicas() { + table.AddRow("REPLICAS", *instance.Replicas) + table.AddSeparator() + } + if instance.HasFlavor() { + table.AddRow("CPU", utils.PtrString(instance.Flavor.Cpu)) + table.AddSeparator() + table.AddRow("RAM (GB)", utils.PtrString(instance.Flavor.Memory)) + table.AddSeparator() + } + table.AddRow("BACKUP SCHEDULE (UTC)", utils.PtrString(instance.BackupSchedule)) table.AddSeparator() err = table.Display(p) if err != nil { diff --git a/internal/cmd/mongodbflex/instance/list/list.go b/internal/cmd/mongodbflex/instance/list/list.go index d76c3d667..40ac2ef8d 100644 --- a/internal/cmd/mongodbflex/instance/list/list.go +++ b/internal/cmd/mongodbflex/instance/list/list.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" @@ -152,7 +153,11 @@ func outputResult(p *print.Printer, outputFormat string, instances []mongodbflex table.SetHeader("ID", "NAME", "STATUS") for i := range instances { instance := instances[i] - table.AddRow(*instance.Id, *instance.Name, *instance.Status) + table.AddRow( + utils.PtrString(instance.Id), + utils.PtrString(instance.Name), + utils.PtrString(instance.Status), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/mongodbflex/options/options.go b/internal/cmd/mongodbflex/options/options.go index e58a5e311..abe1cca69 100644 --- a/internal/cmd/mongodbflex/options/options.go +++ b/internal/cmd/mongodbflex/options/options.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" @@ -13,8 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" ) @@ -231,7 +231,13 @@ func buildFlavorsTable(flavors []mongodbflex.HandlersInfraFlavor) tables.Table { table.SetHeader("ID", "CPU", "MEMORY", "DESCRIPTION", "VALID INSTANCE TYPES") for i := range flavors { f := flavors[i] - table.AddRow(*f.Id, *f.Cpu, *f.Memory, *f.Description, *f.Categories) + table.AddRow( + utils.PtrString(f.Id), + utils.PtrString(f.Cpu), + utils.PtrString(f.Memory), + utils.PtrString(f.Description), + utils.PtrString(f.Categories), + ) } return table } @@ -254,7 +260,11 @@ func buildStoragesTable(storagesResp mongodbflex.ListStoragesResponse) tables.Ta table.SetHeader("MINIMUM", "MAXIMUM", "STORAGE CLASS") for i := range storages { sc := storages[i] - table.AddRow(*storagesResp.StorageRange.Min, *storagesResp.StorageRange.Max, sc) + table.AddRow( + utils.PtrString(storagesResp.StorageRange.Min), + utils.PtrString(storagesResp.StorageRange.Max), + sc, + ) } table.EnableAutoMergeOnColumns(1, 2, 3) return table diff --git a/internal/cmd/mongodbflex/user/create/create.go b/internal/cmd/mongodbflex/user/create/create.go index 350142390..f3744c3cb 100644 --- a/internal/cmd/mongodbflex/user/create/create.go +++ b/internal/cmd/mongodbflex/user/create/create.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" ) @@ -167,14 +168,14 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, use return nil default: - p.Outputf("Created user for instance %q. User ID: %s\n\n", instanceLabel, *user.Id) - p.Outputf("Username: %s\n", *user.Username) - p.Outputf("Password: %s\n", *user.Password) - p.Outputf("Roles: %v\n", *user.Roles) - p.Outputf("Database: %s\n", *user.Database) - p.Outputf("Host: %s\n", *user.Host) - p.Outputf("Port: %d\n", *user.Port) - p.Outputf("URI: %s\n", *user.Uri) + p.Outputf("Created user for instance %q. User ID: %s\n\n", instanceLabel, utils.PtrString(user.Id)) + p.Outputf("Username: %s\n", utils.PtrString(user.Username)) + p.Outputf("Password: %s\n", utils.PtrString(user.Password)) + p.Outputf("Roles: %v\n", utils.PtrString(user.Roles)) + p.Outputf("Database: %s\n", utils.PtrString(user.Database)) + p.Outputf("Host: %s\n", utils.PtrString(user.Host)) + p.Outputf("Port: %s\n", utils.PtrString(user.Port)) + p.Outputf("URI: %s\n", utils.PtrString(user.Uri)) return nil } diff --git a/internal/cmd/mongodbflex/user/describe/describe.go b/internal/cmd/mongodbflex/user/describe/describe.go index c3eb9d5cc..5f95804a3 100644 --- a/internal/cmd/mongodbflex/user/describe/describe.go +++ b/internal/cmd/mongodbflex/user/describe/describe.go @@ -137,17 +137,17 @@ func outputResult(p *print.Printer, outputFormat string, user mongodbflex.Instan return nil default: table := tables.NewTable() - table.AddRow("ID", *user.Id) + table.AddRow("ID", utils.PtrString(user.Id)) table.AddSeparator() - table.AddRow("USERNAME", *user.Username) + table.AddRow("USERNAME", utils.PtrString(user.Username)) table.AddSeparator() - table.AddRow("ROLES", *user.Roles) + table.AddRow("ROLES", utils.PtrString(user.Roles)) table.AddSeparator() - table.AddRow("DATABASE", *user.Database) + table.AddRow("DATABASE", utils.PtrString(user.Database)) table.AddSeparator() - table.AddRow("HOST", *user.Host) + table.AddRow("HOST", utils.PtrString(user.Host)) table.AddSeparator() - table.AddRow("PORT", *user.Port) + table.AddRow("PORT", utils.PtrString(user.Port)) err := table.Display(p) if err != nil { diff --git a/internal/cmd/mongodbflex/user/list/list.go b/internal/cmd/mongodbflex/user/list/list.go index 8ba1f3908..365f5ee36 100644 --- a/internal/cmd/mongodbflex/user/list/list.go +++ b/internal/cmd/mongodbflex/user/list/list.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" @@ -160,7 +161,10 @@ func outputResult(p *print.Printer, outputFormat string, users []mongodbflex.Lis table.SetHeader("ID", "USERNAME") for i := range users { user := users[i] - table.AddRow(*user.Id, *user.Username) + table.AddRow( + utils.PtrString(user.Id), + utils.PtrString(user.Username), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/mongodbflex/user/reset-password/reset_password.go b/internal/cmd/mongodbflex/user/reset-password/reset_password.go index 665ad9b8b..e04fa7b90 100644 --- a/internal/cmd/mongodbflex/user/reset-password/reset_password.go +++ b/internal/cmd/mongodbflex/user/reset-password/reset_password.go @@ -153,9 +153,9 @@ func outputResult(p *print.Printer, model *inputModel, userLabel, instanceLabel return nil default: p.Outputf("Reset password for user %q of instance %q\n\n", userLabel, instanceLabel) - p.Outputf("Username: %s\n", *user.Username) - p.Outputf("New password: %s\n", *user.Password) - p.Outputf("New URI: %s\n", *user.Uri) + p.Outputf("Username: %s\n", utils.PtrString(user.Username)) + p.Outputf("New password: %s\n", utils.PtrString(user.Password)) + p.Outputf("New URI: %s\n", utils.PtrString(user.Uri)) return nil } } diff --git a/internal/cmd/object-storage/bucket/describe/describe.go b/internal/cmd/object-storage/bucket/describe/describe.go index 4196de7bc..f23a2fc85 100644 --- a/internal/cmd/object-storage/bucket/describe/describe.go +++ b/internal/cmd/object-storage/bucket/describe/describe.go @@ -13,6 +13,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" @@ -116,13 +117,13 @@ func outputResult(p *print.Printer, outputFormat string, bucket *objectstorage.B return nil default: table := tables.NewTable() - table.AddRow("Name", *bucket.Name) + table.AddRow("Name", utils.PtrString(bucket.Name)) table.AddSeparator() - table.AddRow("Region", *bucket.Region) + table.AddRow("Region", utils.PtrString(bucket.Region)) table.AddSeparator() - table.AddRow("URL (Path Style)", *bucket.UrlPathStyle) + table.AddRow("URL (Path Style)", utils.PtrString(bucket.UrlPathStyle)) table.AddSeparator() - table.AddRow("URL (Virtual Hosted Style)", *bucket.UrlVirtualHostedStyle) + table.AddRow("URL (Virtual Hosted Style)", utils.PtrString(bucket.UrlVirtualHostedStyle)) table.AddSeparator() err := table.Display(p) if err != nil { diff --git a/internal/cmd/object-storage/bucket/list/list.go b/internal/cmd/object-storage/bucket/list/list.go index 554e6b6c4..d9409ff45 100644 --- a/internal/cmd/object-storage/bucket/list/list.go +++ b/internal/cmd/object-storage/bucket/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" ) @@ -152,7 +152,12 @@ func outputResult(p *print.Printer, outputFormat string, buckets []objectstorage table.SetHeader("NAME", "REGION", "URL (PATH STYLE)", "URL (VIRTUAL HOSTED STYLE)") for i := range buckets { bucket := buckets[i] - table.AddRow(*bucket.Name, *bucket.Region, *bucket.UrlPathStyle, *bucket.UrlVirtualHostedStyle) + table.AddRow( + utils.PtrString(bucket.Name), + utils.PtrString(bucket.Region), + utils.PtrString(bucket.UrlPathStyle), + utils.PtrString(bucket.UrlVirtualHostedStyle), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/object-storage/credentials-group/create/create.go b/internal/cmd/object-storage/credentials-group/create/create.go index c75a145ef..9a611b5b3 100644 --- a/internal/cmd/object-storage/credentials-group/create/create.go +++ b/internal/cmd/object-storage/credentials-group/create/create.go @@ -131,8 +131,11 @@ func outputResult(p *print.Printer, model *inputModel, resp *objectstorage.Creat return nil default: - p.Outputf("Created credentials group %q. Credentials group ID: %s\n\n", *resp.CredentialsGroup.DisplayName, *resp.CredentialsGroup.CredentialsGroupId) - p.Outputf("URN: %s\n", *resp.CredentialsGroup.Urn) + p.Outputf("Created credentials group %q. Credentials group ID: %s\n\n", + utils.PtrString(resp.CredentialsGroup.DisplayName), + utils.PtrString(resp.CredentialsGroup.CredentialsGroupId), + ) + p.Outputf("URN: %s\n", utils.PtrString(resp.CredentialsGroup.Urn)) return nil } } diff --git a/internal/cmd/object-storage/credentials-group/list/list.go b/internal/cmd/object-storage/credentials-group/list/list.go index 416eef811..7f2962c23 100644 --- a/internal/cmd/object-storage/credentials-group/list/list.go +++ b/internal/cmd/object-storage/credentials-group/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" ) @@ -144,7 +144,11 @@ func outputResult(p *print.Printer, outputFormat string, credentialsGroups []obj table.SetHeader("ID", "NAME", "URN") for i := range credentialsGroups { c := credentialsGroups[i] - table.AddRow(*c.CredentialsGroupId, *c.DisplayName, *c.Urn) + table.AddRow( + utils.PtrString(c.CredentialsGroupId), + utils.PtrString(c.DisplayName), + utils.PtrString(c.Urn), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/object-storage/credentials/create/create.go b/internal/cmd/object-storage/credentials/create/create.go index a4cdab240..1e659cdb7 100644 --- a/internal/cmd/object-storage/credentials/create/create.go +++ b/internal/cmd/object-storage/credentials/create/create.go @@ -7,8 +7,6 @@ import ( "time" "github.com/goccy/go-yaml" - objectStorageUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/utils" - "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -17,6 +15,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" + objectStorageUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" ) @@ -161,9 +161,9 @@ func outputResult(p *print.Printer, model *inputModel, credentialsGroupLabel str expireDate = *resp.Expires } - p.Outputf("Created credentials in group %q. Credentials ID: %s\n\n", credentialsGroupLabel, *resp.KeyId) - p.Outputf("Access Key ID: %s\n", *resp.AccessKey) - p.Outputf("Secret Access Key: %s\n", *resp.SecretAccessKey) + p.Outputf("Created credentials in group %q. Credentials ID: %s\n\n", credentialsGroupLabel, utils.PtrString(resp.KeyId)) + p.Outputf("Access Key ID: %s\n", utils.PtrString(resp.AccessKey)) + p.Outputf("Secret Access Key: %s\n", utils.PtrString(resp.SecretAccessKey)) p.Outputf("Expire Date: %s\n", expireDate) return nil diff --git a/internal/cmd/object-storage/credentials/list/list.go b/internal/cmd/object-storage/credentials/list/list.go index da2643610..237d74c61 100644 --- a/internal/cmd/object-storage/credentials/list/list.go +++ b/internal/cmd/object-storage/credentials/list/list.go @@ -6,8 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" - objectStorageUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/utils" - + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,9 +14,9 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" + objectStorageUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" ) @@ -161,11 +160,8 @@ func outputResult(p *print.Printer, outputFormat string, credentials []objectsto for i := range credentials { c := credentials[i] - expiresAt := "Never" - if c.Expires != nil { - expiresAt = *c.Expires - } - table.AddRow(*c.KeyId, *c.DisplayName, expiresAt) + expiresAt := utils.PtrStringDefault(c.Expires, "Never") + table.AddRow(utils.PtrString(c.KeyId), utils.PtrString(c.DisplayName), expiresAt) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/observability/credentials/create/create.go b/internal/cmd/observability/credentials/create/create.go index d74983441..6ee744588 100644 --- a/internal/cmd/observability/credentials/create/create.go +++ b/internal/cmd/observability/credentials/create/create.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/client" observabilityUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/observability" ) @@ -135,7 +136,9 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res p.Outputf("Username: %s\n", username) } - p.Outputf("Password: %s\n", *resp.Credentials.Password) + if resp.Credentials != nil { + p.Outputf("Password: %s\n", utils.PtrString(resp.Credentials.Password)) + } return nil } } diff --git a/internal/cmd/observability/credentials/list/list.go b/internal/cmd/observability/credentials/list/list.go index 29096de24..397f1c6a9 100644 --- a/internal/cmd/observability/credentials/list/list.go +++ b/internal/cmd/observability/credentials/list/list.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/client" observabilityUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/observability" @@ -146,7 +147,7 @@ func outputResult(p *print.Printer, outputFormat string, credentials []observabi table.SetHeader("USERNAME") for i := range credentials { c := credentials[i] - table.AddRow(*c.Name) + table.AddRow(utils.PtrString(c.Name)) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/observability/grafana/describe/describe.go b/internal/cmd/observability/grafana/describe/describe.go index d21258329..9c50a7c6a 100644 --- a/internal/cmd/observability/grafana/describe/describe.go +++ b/internal/cmd/observability/grafana/describe/describe.go @@ -149,13 +149,13 @@ func outputResult(p *print.Printer, inputModel *inputModel, grafanaConfigs *obse } table := tables.NewTable() - table.AddRow("GRAFANA DASHBOARD", *instance.Instance.GrafanaUrl) + table.AddRow("GRAFANA DASHBOARD", utils.PtrString(instance.Instance.GrafanaUrl)) table.AddSeparator() - table.AddRow("PUBLIC READ ACCESS", *grafanaConfigs.PublicReadAccess) + table.AddRow("PUBLIC READ ACCESS", utils.PtrString(grafanaConfigs.PublicReadAccess)) table.AddSeparator() - table.AddRow("SINGLE SIGN-ON", *grafanaConfigs.UseStackitSso) + table.AddRow("SINGLE SIGN-ON", utils.PtrString(grafanaConfigs.UseStackitSso)) table.AddSeparator() - table.AddRow("INITIAL ADMIN USER (DEFAULT)", *instance.Instance.GrafanaAdminUser) + table.AddRow("INITIAL ADMIN USER (DEFAULT)", utils.PtrString(instance.Instance.GrafanaAdminUser)) table.AddSeparator() table.AddRow("INITIAL ADMIN PASSWORD (DEFAULT)", initialAdminPassword) err := table.Display(p) diff --git a/internal/cmd/observability/instance/create/create.go b/internal/cmd/observability/instance/create/create.go index 02057ddbe..134b8388e 100644 --- a/internal/cmd/observability/instance/create/create.go +++ b/internal/cmd/observability/instance/create/create.go @@ -16,6 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" observabilityUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/utils" @@ -222,7 +223,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, *resp.InstanceId) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, utils.PtrString(resp.InstanceId)) return nil } } diff --git a/internal/cmd/observability/instance/describe/describe.go b/internal/cmd/observability/instance/describe/describe.go index 9f3764e00..dfd0717c7 100644 --- a/internal/cmd/observability/instance/describe/describe.go +++ b/internal/cmd/observability/instance/describe/describe.go @@ -117,26 +117,30 @@ func outputResult(p *print.Printer, outputFormat string, instance *observability return nil default: table := tables.NewTable() - table.AddRow("ID", *instance.Id) + table.AddRow("ID", utils.PtrString(instance.Id)) table.AddSeparator() - table.AddRow("NAME", *instance.Name) + table.AddRow("NAME", utils.PtrString(instance.Name)) table.AddSeparator() - table.AddRow("STATUS", *instance.Status) + table.AddRow("STATUS", utils.PtrString(instance.Status)) table.AddSeparator() - table.AddRow("PLAN NAME", *instance.PlanName) - table.AddSeparator() - table.AddRow("METRIC SAMPLES (PER MIN)", *instance.Instance.Plan.TotalMetricSamples) - table.AddSeparator() - table.AddRow("LOGS (GB)", *instance.Instance.Plan.LogsStorage) - table.AddSeparator() - table.AddRow("TRACES (GB)", *instance.Instance.Plan.TracesStorage) - table.AddSeparator() - table.AddRow("NOTIFICATION RULES", *instance.Instance.Plan.AlertRules) - table.AddSeparator() - table.AddRow("GRAFANA USERS", *instance.Instance.Plan.GrafanaGlobalUsers) - table.AddSeparator() - table.AddRow("GRAFANA URL", *instance.Instance.GrafanaUrl) + table.AddRow("PLAN NAME", utils.PtrString(instance.PlanName)) table.AddSeparator() + if inst := instance.Instance; inst != nil { + if plan := inst.Plan; plan != nil { + table.AddRow("METRIC SAMPLES (PER MIN)", utils.PtrString(plan.TotalMetricSamples)) + table.AddSeparator() + table.AddRow("LOGS (GB)", utils.PtrString(plan.LogsStorage)) + table.AddSeparator() + table.AddRow("TRACES (GB)", utils.PtrString(plan.TracesStorage)) + table.AddSeparator() + table.AddRow("NOTIFICATION RULES", utils.PtrString(plan.AlertRules)) + table.AddSeparator() + table.AddRow("GRAFANA USERS", utils.PtrString(plan.GrafanaGlobalUsers)) + table.AddSeparator() + } + table.AddRow("GRAFANA URL", utils.PtrString(inst.GrafanaUrl)) + table.AddSeparator() + } err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) diff --git a/internal/cmd/observability/instance/list/list.go b/internal/cmd/observability/instance/list/list.go index 1db4743c3..db212da21 100644 --- a/internal/cmd/observability/instance/list/list.go +++ b/internal/cmd/observability/instance/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/observability" ) @@ -152,7 +152,12 @@ func outputResult(p *print.Printer, outputFormat string, instances []observabili table.SetHeader("ID", "NAME", "PLAN", "STATUS") for i := range instances { instance := instances[i] - table.AddRow(*instance.Id, *instance.Name, *instance.PlanName, *instance.Status) + table.AddRow( + utils.PtrString(instance.Id), + utils.PtrString(instance.Name), + utils.PtrString(instance.PlanName), + utils.PtrString(instance.Status), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/observability/plans/plans.go b/internal/cmd/observability/plans/plans.go index 2a62612e2..872d5efea 100644 --- a/internal/cmd/observability/plans/plans.go +++ b/internal/cmd/observability/plans/plans.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" - "github.com/goccy/go-yaml" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,7 +14,9 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" + "github.com/goccy/go-yaml" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/observability" ) @@ -152,7 +153,11 @@ func outputResult(p *print.Printer, outputFormat string, plans []observability.P table.SetHeader("ID", "PLAN NAME", "DESCRIPTION") for i := range plans { o := plans[i] - table.AddRow(*o.Id, *o.Name, *o.Description) + table.AddRow( + utils.PtrString(o.Id), + utils.PtrString(o.Name), + utils.PtrString(o.Description), + ) table.AddSeparator() } table.EnableAutoMergeOnColumns(1) diff --git a/internal/cmd/observability/scrape-config/create/create.go b/internal/cmd/observability/scrape-config/create/create.go index 545a706c2..0856e6b19 100644 --- a/internal/cmd/observability/scrape-config/create/create.go +++ b/internal/cmd/observability/scrape-config/create/create.go @@ -14,6 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/client" observabilityUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/observability" @@ -118,7 +119,7 @@ func NewCmd(p *print.Printer) *cobra.Command { if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s scrape configuration with name %q for Observability instance %q\n", operationState, *jobName, instanceLabel) + p.Outputf("%s scrape configuration with name %q for Observability instance %q\n", operationState, utils.PtrString(jobName), instanceLabel) return nil }, } diff --git a/internal/cmd/observability/scrape-config/describe/describe.go b/internal/cmd/observability/scrape-config/describe/describe.go index 9a94c8fd6..37dd359e7 100644 --- a/internal/cmd/observability/scrape-config/describe/describe.go +++ b/internal/cmd/observability/scrape-config/describe/describe.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,9 +16,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/observability" - - "github.com/spf13/cobra" ) const ( @@ -147,15 +147,15 @@ func outputResult(p *print.Printer, outputFormat string, config *observability.J } table := tables.NewTable() - table.AddRow("NAME", *config.JobName) + table.AddRow("NAME", utils.PtrString(config.JobName)) table.AddSeparator() - table.AddRow("METRICS PATH", *config.MetricsPath) + table.AddRow("METRICS PATH", utils.PtrString(config.MetricsPath)) table.AddSeparator() - table.AddRow("SCHEME", *config.Scheme) + table.AddRow("SCHEME", utils.PtrString(config.Scheme)) table.AddSeparator() - table.AddRow("SCRAPE INTERVAL", *config.ScrapeInterval) + table.AddRow("SCRAPE INTERVAL", utils.PtrString(config.ScrapeInterval)) table.AddSeparator() - table.AddRow("SCRAPE TIMEOUT", *config.ScrapeTimeout) + table.AddRow("SCRAPE TIMEOUT", utils.PtrString(config.ScrapeTimeout)) table.AddSeparator() table.AddRow("SAML2", saml2Enabled) table.AddSeparator() @@ -164,9 +164,9 @@ func outputResult(p *print.Printer, outputFormat string, config *observability.J } else { table.AddRow("AUTHENTICATION", "Basic Auth") table.AddSeparator() - table.AddRow("USERNAME", *config.BasicAuth.Username) + table.AddRow("USERNAME", utils.PtrString(config.BasicAuth.Username)) table.AddSeparator() - table.AddRow("PASSWORD", *config.BasicAuth.Password) + table.AddRow("PASSWORD", utils.PtrString(config.BasicAuth.Password)) } table.AddSeparator() for i, target := range targets { diff --git a/internal/cmd/observability/scrape-config/list/list.go b/internal/cmd/observability/scrape-config/list/list.go index b1a33f886..6e2543869 100644 --- a/internal/cmd/observability/scrape-config/list/list.go +++ b/internal/cmd/observability/scrape-config/list/list.go @@ -14,6 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" observabilityUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/utils" @@ -160,7 +161,11 @@ func outputResult(p *print.Printer, outputFormat string, configs []observability } } - table.AddRow(*c.JobName, targets, *c.ScrapeInterval) + table.AddRow( + utils.PtrString(c.JobName), + targets, + utils.PtrString(c.ScrapeInterval), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/opensearch/credentials/create/create.go b/internal/cmd/opensearch/credentials/create/create.go index 44cef8420..015c41cc9 100644 --- a/internal/cmd/opensearch/credentials/create/create.go +++ b/internal/cmd/opensearch/credentials/create/create.go @@ -145,18 +145,20 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res return nil default: - p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) // The username field cannot be set by the user so we only display it if it's not returned empty - username := *resp.Raw.Credentials.Username - if username != "" { - p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) - } - if !model.ShowPassword { - p.Outputf("Password: \n") - } else { - p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) + p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, utils.PtrString(resp.Id)) + // The username field cannot be set by the user so we only display it if it's not returned empty + if resp.HasRaw() && resp.Raw.Credentials != nil { + if username := resp.Raw.Credentials.Username; username != nil && *username != "" { + p.Outputf("Username: %s\n", *username) + } + if !model.ShowPassword { + p.Outputf("Password: \n") + } else { + p.Outputf("Password: %s\n", utils.PtrString(resp.Raw.Credentials.Password)) + } + p.Outputf("Host: %s\n", utils.PtrString(resp.Raw.Credentials.Host)) + p.Outputf("Port: %s\n", utils.PtrString(resp.Raw.Credentials.Port)) } - p.Outputf("Host: %s\n", *resp.Raw.Credentials.Host) - p.Outputf("Port: %d\n", *resp.Raw.Credentials.Port) p.Outputf("URI: %s\n", *resp.Uri) return nil } diff --git a/internal/cmd/opensearch/credentials/describe/describe.go b/internal/cmd/opensearch/credentials/describe/describe.go index 596ffc3eb..838521396 100644 --- a/internal/cmd/opensearch/credentials/describe/describe.go +++ b/internal/cmd/opensearch/credentials/describe/describe.go @@ -131,17 +131,18 @@ func outputResult(p *print.Printer, outputFormat string, credentials *opensearch return nil default: table := tables.NewTable() - table.AddRow("ID", *credentials.Id) + table.AddRow("ID", utils.PtrString(credentials.Id)) table.AddSeparator() // The username field cannot be set by the user so we only display it if it's not returned empty - username := *credentials.Raw.Credentials.Username - if username != "" { - table.AddRow("USERNAME", *credentials.Raw.Credentials.Username) + if credentials.HasRaw() && credentials.Raw.Credentials != nil { + if username := credentials.Raw.Credentials.Username; username != nil && *username != "" { + table.AddRow("USERNAME", *username) + table.AddSeparator() + } + table.AddRow("PASSWORD", utils.PtrString(credentials.Raw.Credentials.Password)) table.AddSeparator() + table.AddRow("URI", utils.PtrString(credentials.Raw.Credentials.Uri)) } - table.AddRow("PASSWORD", *credentials.Raw.Credentials.Password) - table.AddSeparator() - table.AddRow("URI", *credentials.Raw.Credentials.Uri) err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) diff --git a/internal/cmd/opensearch/credentials/list/list.go b/internal/cmd/opensearch/credentials/list/list.go index a6e1a8e48..7f5636691 100644 --- a/internal/cmd/opensearch/credentials/list/list.go +++ b/internal/cmd/opensearch/credentials/list/list.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" - "github.com/goccy/go-yaml" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,7 +14,9 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" opensearchUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" + "github.com/goccy/go-yaml" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/opensearch" ) @@ -157,7 +158,7 @@ func outputResult(p *print.Printer, outputFormat string, credentials []opensearc table.SetHeader("ID") for i := range credentials { c := credentials[i] - table.AddRow(*c.Id) + table.AddRow(utils.PtrString(c.Id)) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/opensearch/instance/describe/describe.go b/internal/cmd/opensearch/instance/describe/describe.go index b1f06faff..8fd2f081b 100644 --- a/internal/cmd/opensearch/instance/describe/describe.go +++ b/internal/cmd/opensearch/instance/describe/describe.go @@ -119,15 +119,15 @@ func outputResult(p *print.Printer, outputFormat string, instance *opensearch.In return nil default: table := tables.NewTable() - table.AddRow("ID", *instance.InstanceId) + table.AddRow("ID", utils.PtrString(instance.InstanceId)) table.AddSeparator() - table.AddRow("NAME", *instance.Name) + table.AddRow("NAME", utils.PtrString(instance.Name)) table.AddSeparator() - table.AddRow("LAST OPERATION TYPE", *instance.LastOperation.Type) + table.AddRow("LAST OPERATION TYPE", utils.PtrString(instance.LastOperation.Type)) table.AddSeparator() - table.AddRow("LAST OPERATION STATE", *instance.LastOperation.State) + table.AddRow("LAST OPERATION STATE", utils.PtrString(instance.LastOperation.State)) table.AddSeparator() - table.AddRow("PLAN ID", *instance.PlanId) + table.AddRow("PLAN ID", utils.PtrString(instance.PlanId)) // Only show ACL if it's present and not empty acl := (*instance.Parameters)[aclParameterKey] aclStr, ok := acl.(string) diff --git a/internal/cmd/opensearch/instance/list/list.go b/internal/cmd/opensearch/instance/list/list.go index dc116b510..c53fa0176 100644 --- a/internal/cmd/opensearch/instance/list/list.go +++ b/internal/cmd/opensearch/instance/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/opensearch" ) @@ -152,7 +152,12 @@ func outputResult(p *print.Printer, outputFormat string, instances []opensearch. table.SetHeader("ID", "NAME", "LAST OPERATION TYPE", "LAST OPERATION STATE") for i := range instances { instance := instances[i] - table.AddRow(*instance.InstanceId, *instance.Name, *instance.LastOperation.Type, *instance.LastOperation.State) + table.AddRow( + utils.PtrString(instance.InstanceId), + utils.PtrString(instance.Name), + utils.PtrString(instance.LastOperation.Type), + utils.PtrString(instance.LastOperation.State), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/opensearch/plans/plans.go b/internal/cmd/opensearch/plans/plans.go index 89409a89a..f72dc67a1 100644 --- a/internal/cmd/opensearch/plans/plans.go +++ b/internal/cmd/opensearch/plans/plans.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/opensearch" @@ -154,7 +155,13 @@ func outputResult(p *print.Printer, outputFormat string, plans []opensearch.Offe o := plans[i] for j := range *o.Plans { plan := (*o.Plans)[j] - table.AddRow(*o.Name, *o.Version, *plan.Id, *plan.Name, *plan.Description) + table.AddRow( + utils.PtrString(o.Name), + utils.PtrString(o.Version), + utils.PtrString(plan.Id), + utils.PtrString(plan.Name), + utils.PtrString(plan.Description), + ) } table.AddSeparator() } diff --git a/internal/cmd/organization/member/list/list.go b/internal/cmd/organization/member/list/list.go index 8ff1a1826..3a4c38a41 100644 --- a/internal/cmd/organization/member/list/list.go +++ b/internal/cmd/organization/member/list/list.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/authorization" @@ -183,7 +184,7 @@ func outputResult(p *print.Printer, model *inputModel, members []authorization.M if i > 0 && sortFn(i-1, i) { table.AddSeparator() } - table.AddRow(*m.Subject, *m.Role) + table.AddRow(utils.PtrString(m.Subject), utils.PtrString(m.Role)) } if model.SortBy == "subject" { diff --git a/internal/cmd/organization/role/list/list.go b/internal/cmd/organization/role/list/list.go index 6d62f190e..51e9390af 100644 --- a/internal/cmd/organization/role/list/list.go +++ b/internal/cmd/organization/role/list/list.go @@ -14,6 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/authorization" @@ -154,7 +155,12 @@ func outputRolesResult(p *print.Printer, outputFormat string, roles []authorizat r := roles[i] for j := range *r.Permissions { p := (*r.Permissions)[j] - table.AddRow(*r.Name, *r.Description, *p.Name, *p.Description) + table.AddRow( + utils.PtrString(r.Name), + utils.PtrString(r.Description), + utils.PtrString(p.Name), + utils.PtrString(p.Description), + ) } table.AddSeparator() } diff --git a/internal/cmd/postgresflex/backup/describe/describe.go b/internal/cmd/postgresflex/backup/describe/describe.go index 9e306e2b4..10c3bdda8 100644 --- a/internal/cmd/postgresflex/backup/describe/describe.go +++ b/internal/cmd/postgresflex/backup/describe/describe.go @@ -4,11 +4,9 @@ import ( "context" "encoding/json" "fmt" - "time" "github.com/goccy/go-yaml" - "github.com/inhies/go-bytesize" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -18,6 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" ) @@ -133,13 +132,15 @@ func outputResult(p *print.Printer, cmd *cobra.Command, outputFormat string, bac return nil default: table := tables.NewTable() - table.AddRow("ID", *backup.Id) + table.AddRow("ID", utils.PtrString(backup.Id)) table.AddSeparator() - table.AddRow("CREATED AT", *backup.StartTime) + table.AddRow("CREATED AT", utils.PtrString(backup.StartTime)) table.AddSeparator() table.AddRow("EXPIRES AT", backupExpireDate) table.AddSeparator() - table.AddRow("BACKUP SIZE", bytesize.New(float64(*backup.Size))) + + backupSize := utils.PtrByteSizeDefault(backup.Size, "n/a") + table.AddRow("BACKUP SIZE", backupSize) err := table.Display(p) if err != nil { diff --git a/internal/cmd/postgresflex/backup/list/list.go b/internal/cmd/postgresflex/backup/list/list.go index 519b2065f..c03a3afb6 100644 --- a/internal/cmd/postgresflex/backup/list/list.go +++ b/internal/cmd/postgresflex/backup/list/list.go @@ -6,7 +6,6 @@ import ( "fmt" "github.com/goccy/go-yaml" - "github.com/inhies/go-bytesize" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -16,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "time" @@ -163,7 +163,13 @@ func outputResult(p *print.Printer, outputFormat string, backups []postgresflex. } backupExpireDate := backupStartTime.AddDate(backupExpireYearOffset, backupExpireMonthOffset, backupExpireDayOffset).Format(time.DateOnly) - table.AddRow(*backup.Id, *backup.StartTime, backupExpireDate, bytesize.New(float64(*backup.Size))) + backupSize := utils.PtrByteSizeDefault(backup.Size, "n/a") + table.AddRow( + utils.PtrString(backup.Id), + utils.PtrString(backup.StartTime), + backupExpireDate, + backupSize, + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/postgresflex/instance/describe/describe.go b/internal/cmd/postgresflex/instance/describe/describe.go index 3ca2e291a..404a1c23d 100644 --- a/internal/cmd/postgresflex/instance/describe/describe.go +++ b/internal/cmd/postgresflex/instance/describe/describe.go @@ -120,8 +120,11 @@ func outputResult(p *print.Printer, outputFormat string, instance *postgresflex. return nil default: - aclsArray := *instance.Acl.Items - acls := strings.Join(aclsArray, ",") + acls := "" + if instance.HasAcl() && instance.Acl.HasItems() { + aclsArray := *instance.Acl.Items + acls = strings.Join(aclsArray, ",") + } instanceType, err := postgresflexUtils.GetInstanceType(*instance.Replicas) if err != nil { @@ -130,29 +133,29 @@ func outputResult(p *print.Printer, outputFormat string, instance *postgresflex. } table := tables.NewTable() - table.AddRow("ID", *instance.Id) + table.AddRow("ID", utils.PtrString(instance.Id)) table.AddSeparator() - table.AddRow("NAME", *instance.Name) + table.AddRow("NAME", utils.PtrString(instance.Name)) table.AddSeparator() - table.AddRow("STATUS", cases.Title(language.English).String(*instance.Status)) + table.AddRow("STATUS", cases.Title(language.English).String(utils.PtrString(instance.Status))) table.AddSeparator() - table.AddRow("STORAGE SIZE (GB)", *instance.Storage.Size) + table.AddRow("STORAGE SIZE (GB)", utils.PtrString(instance.Storage.Size)) table.AddSeparator() - table.AddRow("VERSION", *instance.Version) + table.AddRow("VERSION", utils.PtrString(instance.Version)) table.AddSeparator() table.AddRow("ACL", acls) table.AddSeparator() - table.AddRow("FLAVOR DESCRIPTION", *instance.Flavor.Description) + table.AddRow("FLAVOR DESCRIPTION", utils.PtrString(instance.Flavor.Description)) table.AddSeparator() table.AddRow("TYPE", instanceType) table.AddSeparator() - table.AddRow("REPLICAS", *instance.Replicas) + table.AddRow("REPLICAS", utils.PtrString(instance.Replicas)) table.AddSeparator() - table.AddRow("CPU", *instance.Flavor.Cpu) + table.AddRow("CPU", utils.PtrString(instance.Flavor.Cpu)) table.AddSeparator() - table.AddRow("RAM (GB)", *instance.Flavor.Memory) + table.AddRow("RAM (GB)", utils.PtrString(instance.Flavor.Memory)) table.AddSeparator() - table.AddRow("BACKUP SCHEDULE (UTC)", *instance.BackupSchedule) + table.AddRow("BACKUP SCHEDULE (UTC)", utils.PtrString(instance.BackupSchedule)) table.AddSeparator() err = table.Display(p) if err != nil { diff --git a/internal/cmd/postgresflex/instance/list/list.go b/internal/cmd/postgresflex/instance/list/list.go index cb469bfbe..349f7d872 100644 --- a/internal/cmd/postgresflex/instance/list/list.go +++ b/internal/cmd/postgresflex/instance/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" "golang.org/x/text/cases" "golang.org/x/text/language" @@ -155,7 +155,11 @@ func outputResult(p *print.Printer, outputFormat string, instances []postgresfle table.SetHeader("ID", "NAME", "STATUS") for i := range instances { instance := instances[i] - table.AddRow(*instance.Id, *instance.Name, caser.String(*instance.Status)) + table.AddRow( + utils.PtrString(instance.Id), + utils.PtrString(instance.Name), + caser.String(utils.PtrString(instance.Status)), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/postgresflex/options/options.go b/internal/cmd/postgresflex/options/options.go index f5833d151..22950039d 100644 --- a/internal/cmd/postgresflex/options/options.go +++ b/internal/cmd/postgresflex/options/options.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" @@ -13,8 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" ) @@ -179,7 +179,7 @@ func outputResult(p *print.Printer, model *inputModel, flavors *postgresflex.Lis } if storages != nil && model.FlavorId != nil { options.Storages = &flavorStorages{ - FlavorId: *model.FlavorId, + FlavorId: utils.PtrString(model.FlavorId), Storages: storages, } } @@ -231,7 +231,12 @@ func buildFlavorsTable(flavors []postgresflex.Flavor) tables.Table { table.SetHeader("ID", "CPU", "MEMORY", "DESCRIPTION") for i := range flavors { f := flavors[i] - table.AddRow(*f.Id, *f.Cpu, *f.Memory, *f.Description) + table.AddRow( + utils.PtrString(f.Id), + utils.PtrString(f.Cpu), + utils.PtrString(f.Memory), + utils.PtrString(f.Description), + ) } return table } @@ -254,7 +259,11 @@ func buildStoragesTable(storagesResp postgresflex.ListStoragesResponse) tables.T table.SetHeader("MINIMUM", "MAXIMUM", "STORAGE CLASS") for i := range storages { sc := storages[i] - table.AddRow(*storagesResp.StorageRange.Min, *storagesResp.StorageRange.Max, sc) + table.AddRow( + utils.PtrString(storagesResp.StorageRange.Min), + utils.PtrString(storagesResp.StorageRange.Max), + sc, + ) } table.EnableAutoMergeOnColumns(1, 2, 3) return table diff --git a/internal/cmd/postgresflex/user/create/create.go b/internal/cmd/postgresflex/user/create/create.go index c3399ab98..f8d65bf01 100644 --- a/internal/cmd/postgresflex/user/create/create.go +++ b/internal/cmd/postgresflex/user/create/create.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" ) @@ -163,13 +163,13 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res return nil default: user := resp.Item - p.Outputf("Created user for instance %q. User ID: %s\n\n", instanceLabel, *user.Id) - p.Outputf("Username: %s\n", *user.Username) - p.Outputf("Password: %s\n", *user.Password) - p.Outputf("Roles: %v\n", *user.Roles) - p.Outputf("Host: %s\n", *user.Host) - p.Outputf("Port: %d\n", *user.Port) - p.Outputf("URI: %s\n", *user.Uri) + p.Outputf("Created user for instance %q. User ID: %s\n\n", instanceLabel, utils.PtrString(user.Id)) + p.Outputf("Username: %s\n", utils.PtrString(user.Username)) + p.Outputf("Password: %s\n", utils.PtrString(user.Password)) + p.Outputf("Roles: %v\n", utils.PtrString(user.Roles)) + p.Outputf("Host: %s\n", utils.PtrString(user.Host)) + p.Outputf("Port: %s\n", utils.PtrString(user.Port)) + p.Outputf("URI: %s\n", utils.PtrString(user.Uri)) return nil } diff --git a/internal/cmd/postgresflex/user/describe/describe.go b/internal/cmd/postgresflex/user/describe/describe.go index 5855ca07d..b63e08bd7 100644 --- a/internal/cmd/postgresflex/user/describe/describe.go +++ b/internal/cmd/postgresflex/user/describe/describe.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" ) @@ -136,15 +136,15 @@ func outputResult(p *print.Printer, outputFormat string, user postgresflex.UserR return nil default: table := tables.NewTable() - table.AddRow("ID", *user.Id) + table.AddRow("ID", utils.PtrString(user.Id)) table.AddSeparator() - table.AddRow("USERNAME", *user.Username) + table.AddRow("USERNAME", utils.PtrString(user.Username)) table.AddSeparator() - table.AddRow("ROLES", *user.Roles) + table.AddRow("ROLES", utils.PtrString(user.Roles)) table.AddSeparator() - table.AddRow("HOST", *user.Host) + table.AddRow("HOST", utils.PtrString(user.Host)) table.AddSeparator() - table.AddRow("PORT", *user.Port) + table.AddRow("PORT", utils.PtrString(user.Port)) err := table.Display(p) if err != nil { diff --git a/internal/cmd/postgresflex/user/list/list.go b/internal/cmd/postgresflex/user/list/list.go index bb1f601f1..ae76e7958 100644 --- a/internal/cmd/postgresflex/user/list/list.go +++ b/internal/cmd/postgresflex/user/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" ) @@ -160,7 +160,10 @@ func outputResult(p *print.Printer, outputFormat string, users []postgresflex.Li table.SetHeader("ID", "USERNAME") for i := range users { user := users[i] - table.AddRow(*user.Id, *user.Username) + table.AddRow( + utils.PtrString(user.Id), + utils.PtrString(user.Username), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/postgresflex/user/reset-password/reset_password.go b/internal/cmd/postgresflex/user/reset-password/reset_password.go index 77c881189..35d097168 100644 --- a/internal/cmd/postgresflex/user/reset-password/reset_password.go +++ b/internal/cmd/postgresflex/user/reset-password/reset_password.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" ) @@ -152,9 +152,9 @@ func outputResult(p *print.Printer, model *inputModel, userLabel, instanceLabel return nil default: p.Outputf("Reset password for user %q of instance %q\n\n", userLabel, instanceLabel) - p.Outputf("Username: %s\n", *user.Item.Username) - p.Outputf("New password: %s\n", *user.Item.Password) - p.Outputf("New URI: %s\n", *user.Item.Uri) + p.Outputf("Username: %s\n", utils.PtrString(user.Item.Username)) + p.Outputf("New password: %s\n", utils.PtrString(user.Item.Password)) + p.Outputf("New URI: %s\n", utils.PtrString(user.Item.Uri)) return nil } } diff --git a/internal/cmd/project/create/create.go b/internal/cmd/project/create/create.go index 23b0cd9fc..bb67f8cf1 100644 --- a/internal/cmd/project/create/create.go +++ b/internal/cmd/project/create/create.go @@ -231,7 +231,7 @@ func outputResult(p *print.Printer, model *inputModel, resp *resourcemanager.Pro return nil default: - p.Outputf("Created project under the parent with ID %q. Project ID: %s\n", *model.ParentId, *resp.ProjectId) + p.Outputf("Created project under the parent with ID %q. Project ID: %s\n", utils.PtrString(model.ParentId), utils.PtrString(resp.ProjectId)) return nil } } diff --git a/internal/cmd/project/describe/describe.go b/internal/cmd/project/describe/describe.go index 69662f53f..a9d948e67 100644 --- a/internal/cmd/project/describe/describe.go +++ b/internal/cmd/project/describe/describe.go @@ -138,15 +138,15 @@ func outputResult(p *print.Printer, outputFormat string, project *resourcemanage return nil default: table := tables.NewTable() - table.AddRow("ID", *project.ProjectId) + table.AddRow("ID", utils.PtrString(project.ProjectId)) table.AddSeparator() - table.AddRow("NAME", *project.Name) + table.AddRow("NAME", utils.PtrString(project.Name)) table.AddSeparator() - table.AddRow("CREATION", *project.CreationTime) + table.AddRow("CREATION", utils.PtrString(project.CreationTime)) table.AddSeparator() - table.AddRow("STATE", *project.LifecycleState) + table.AddRow("STATE", utils.PtrString(project.LifecycleState)) table.AddSeparator() - table.AddRow("PARENT ID", *project.Parent.Id) + table.AddRow("PARENT ID", utils.PtrString(project.Parent.Id)) err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) diff --git a/internal/cmd/project/list/list.go b/internal/cmd/project/list/list.go index 8b346322c..8c9bb0d8e 100644 --- a/internal/cmd/project/list/list.go +++ b/internal/cmd/project/list/list.go @@ -7,6 +7,7 @@ import ( "time" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -16,8 +17,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/resourcemanager" ) @@ -242,7 +242,12 @@ func outputResult(p *print.Printer, outputFormat string, projects []resourcemana table.SetHeader("ID", "NAME", "STATE", "PARENT ID") for i := range projects { p := projects[i] - table.AddRow(*p.ProjectId, *p.Name, *p.LifecycleState, *p.Parent.Id) + table.AddRow( + utils.PtrString(p.ProjectId), + utils.PtrString(p.Name), + utils.PtrString(p.LifecycleState), + utils.PtrString(p.Parent.Id), + ) } err := table.Display(p) diff --git a/internal/cmd/project/member/add/add.go b/internal/cmd/project/member/add/add.go index d1deff0e8..23436f039 100644 --- a/internal/cmd/project/member/add/add.go +++ b/internal/cmd/project/member/add/add.go @@ -84,7 +84,7 @@ func NewCmd(p *print.Printer) *cobra.Command { return fmt.Errorf("add member: %w", err) } - p.Info("Added the role %q to %s on project %q\n", *model.Role, model.Subject, projectLabel) + p.Info("Added the role %q to %s on project %q\n", utils.PtrString(model.Role), model.Subject, projectLabel) return nil }, } diff --git a/internal/cmd/project/member/list/list.go b/internal/cmd/project/member/list/list.go index 538934344..a95a95fbe 100644 --- a/internal/cmd/project/member/list/list.go +++ b/internal/cmd/project/member/list/list.go @@ -7,6 +7,7 @@ import ( "sort" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -16,8 +17,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) @@ -185,7 +185,7 @@ func outputResult(p *print.Printer, model *inputModel, members []authorization.M if i > 0 && sortFn(i-1, i) { table.AddSeparator() } - table.AddRow(*m.Subject, *m.Role) + table.AddRow(utils.PtrString(m.Subject), utils.PtrString(m.Role)) } if model.SortBy == "subject" { diff --git a/internal/cmd/project/member/remove/remove.go b/internal/cmd/project/member/remove/remove.go index 2c7142b6b..56004a03b 100644 --- a/internal/cmd/project/member/remove/remove.go +++ b/internal/cmd/project/member/remove/remove.go @@ -90,7 +90,7 @@ func NewCmd(p *print.Printer) *cobra.Command { return fmt.Errorf("remove member: %w", err) } - p.Info("Removed the role %q from %s on project %q\n", *model.Role, model.Subject, projectLabel) + p.Info("Removed the role %q from %s on project %q\n", utils.PtrString(model.Role), model.Subject, projectLabel) return nil }, } diff --git a/internal/cmd/project/role/list/list.go b/internal/cmd/project/role/list/list.go index 13b3f79e1..991a00665 100644 --- a/internal/cmd/project/role/list/list.go +++ b/internal/cmd/project/role/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) @@ -156,7 +156,12 @@ func outputRolesResult(p *print.Printer, outputFormat string, roles []authorizat r := roles[i] for j := range *r.Permissions { p := (*r.Permissions)[j] - table.AddRow(*r.Name, *r.Description, *p.Name, *p.Description) + table.AddRow( + utils.PtrString(r.Name), + utils.PtrString(r.Description), + utils.PtrString(p.Name), + utils.PtrString(p.Description), + ) } table.AddSeparator() } diff --git a/internal/cmd/rabbitmq/credentials/create/create.go b/internal/cmd/rabbitmq/credentials/create/create.go index a2b7b09af..2b73dd453 100644 --- a/internal/cmd/rabbitmq/credentials/create/create.go +++ b/internal/cmd/rabbitmq/credentials/create/create.go @@ -144,20 +144,21 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res return nil default: - p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) + p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, utils.PtrString(resp.Id)) // The username field cannot be set by the user so we only display it if it's not returned empty - username := *resp.Raw.Credentials.Username - if username != "" { - p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) - } - if !model.ShowPassword { - p.Outputf("Password: \n") - } else { - p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) + if resp.HasRaw() && resp.Raw.Credentials != nil { + if username := resp.Raw.Credentials.Username; username != nil && *username != "" { + p.Outputf("Username: %s\n", *username) + } + if !model.ShowPassword { + p.Outputf("Password: \n") + } else { + p.Outputf("Password: %s\n", utils.PtrString(resp.Raw.Credentials.Password)) + } + p.Outputf("Host: %s\n", utils.PtrString(resp.Raw.Credentials.Host)) + p.Outputf("Port: %s\n", utils.PtrString(resp.Raw.Credentials.Port)) } - p.Outputf("Host: %s\n", *resp.Raw.Credentials.Host) - p.Outputf("Port: %d\n", *resp.Raw.Credentials.Port) - p.Outputf("URI: %s\n", *resp.Uri) + p.Outputf("URI: %s\n", utils.PtrString(resp.Uri)) return nil } } diff --git a/internal/cmd/rabbitmq/credentials/describe/describe.go b/internal/cmd/rabbitmq/credentials/describe/describe.go index 175488d16..178027280 100644 --- a/internal/cmd/rabbitmq/credentials/describe/describe.go +++ b/internal/cmd/rabbitmq/credentials/describe/describe.go @@ -134,14 +134,15 @@ func outputResult(p *print.Printer, outputFormat string, credentials *rabbitmq.C table.AddRow("ID", *credentials.Id) table.AddSeparator() // The username field cannot be set by the user so we only display it if it's not returned empty - username := *credentials.Raw.Credentials.Username - if username != "" { - table.AddRow("USERNAME", *credentials.Raw.Credentials.Username) + if credentials.HasRaw() && credentials.Raw.Credentials != nil { + if username := credentials.Raw.Credentials.Username; username != nil && *username != "" { + table.AddRow("USERNAME", *username) + table.AddSeparator() + } + table.AddRow("PASSWORD", utils.PtrString(credentials.Raw.Credentials.Password)) table.AddSeparator() + table.AddRow("URI", utils.PtrString(credentials.Raw.Credentials.Uri)) } - table.AddRow("PASSWORD", *credentials.Raw.Credentials.Password) - table.AddSeparator() - table.AddRow("URI", *credentials.Raw.Credentials.Uri) err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) diff --git a/internal/cmd/rabbitmq/credentials/list/list.go b/internal/cmd/rabbitmq/credentials/list/list.go index 95854a129..6911f04c7 100644 --- a/internal/cmd/rabbitmq/credentials/list/list.go +++ b/internal/cmd/rabbitmq/credentials/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" rabbitmqUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq" ) @@ -157,7 +157,7 @@ func outputResult(p *print.Printer, outputFormat string, credentials []rabbitmq. table.SetHeader("ID") for i := range credentials { c := credentials[i] - table.AddRow(*c.Id) + table.AddRow(utils.PtrString(c.Id)) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/rabbitmq/instance/describe/describe.go b/internal/cmd/rabbitmq/instance/describe/describe.go index 4aeb8fdf8..e5038f212 100644 --- a/internal/cmd/rabbitmq/instance/describe/describe.go +++ b/internal/cmd/rabbitmq/instance/describe/describe.go @@ -119,15 +119,15 @@ func outputResult(p *print.Printer, outputFormat string, instance *rabbitmq.Inst return nil default: table := tables.NewTable() - table.AddRow("ID", *instance.InstanceId) + table.AddRow("ID", utils.PtrString(instance.InstanceId)) table.AddSeparator() - table.AddRow("NAME", *instance.Name) + table.AddRow("NAME", utils.PtrString(instance.Name)) table.AddSeparator() - table.AddRow("LAST OPERATION TYPE", *instance.LastOperation.Type) + table.AddRow("LAST OPERATION TYPE", utils.PtrString(instance.LastOperation.Type)) table.AddSeparator() - table.AddRow("LAST OPERATION STATE", *instance.LastOperation.State) + table.AddRow("LAST OPERATION STATE", utils.PtrString(instance.LastOperation.State)) table.AddSeparator() - table.AddRow("PLAN ID", *instance.PlanId) + table.AddRow("PLAN ID", utils.PtrString(instance.PlanId)) // Only show ACL if it's present and not empty acl := (*instance.Parameters)[aclParameterKey] aclStr, ok := acl.(string) diff --git a/internal/cmd/rabbitmq/instance/list/list.go b/internal/cmd/rabbitmq/instance/list/list.go index b5802e849..a371d0f68 100644 --- a/internal/cmd/rabbitmq/instance/list/list.go +++ b/internal/cmd/rabbitmq/instance/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq" ) @@ -152,7 +152,12 @@ func outputResult(p *print.Printer, outputFormat string, instances []rabbitmq.In table.SetHeader("ID", "NAME", "LAST OPERATION TYPE", "LAST OPERATION STATE") for i := range instances { instance := instances[i] - table.AddRow(*instance.InstanceId, *instance.Name, *instance.LastOperation.Type, *instance.LastOperation.State) + table.AddRow( + utils.PtrString(instance.InstanceId), + utils.PtrString(instance.Name), + utils.PtrString(instance.LastOperation.Type), + utils.PtrString(instance.LastOperation.State), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/rabbitmq/plans/plans.go b/internal/cmd/rabbitmq/plans/plans.go index 385858e8f..7255baae7 100644 --- a/internal/cmd/rabbitmq/plans/plans.go +++ b/internal/cmd/rabbitmq/plans/plans.go @@ -15,6 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq" @@ -154,7 +155,13 @@ func outputResult(p *print.Printer, outputFormat string, plans []rabbitmq.Offeri o := plans[i] for j := range *o.Plans { plan := (*o.Plans)[j] - table.AddRow(*o.Name, *o.Version, *plan.Id, *plan.Name, *plan.Description) + table.AddRow( + utils.PtrString(o.Name), + utils.PtrString(o.Version), + utils.PtrString(plan.Id), + utils.PtrString(plan.Name), + utils.PtrString(plan.Description), + ) } table.AddSeparator() } diff --git a/internal/cmd/redis/credentials/create/create.go b/internal/cmd/redis/credentials/create/create.go index f96a6d1a9..e241a2d27 100644 --- a/internal/cmd/redis/credentials/create/create.go +++ b/internal/cmd/redis/credentials/create/create.go @@ -148,18 +148,19 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res default: p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) // The username field cannot be set by the user, so we only display it if it's not returned empty - username := *resp.Raw.Credentials.Username - if username != "" { - p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) - } - if !model.ShowPassword { - p.Outputf("Password: \n") - } else { - p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) + if resp.HasRaw() && resp.Raw.Credentials != nil { + if username := resp.Raw.Credentials.Username; username != nil && *username != "" { + p.Outputf("Username: %s\n", *username) + } + if !model.ShowPassword { + p.Outputf("Password: \n") + } else { + p.Outputf("Password: %s\n", utils.PtrString(resp.Raw.Credentials.Password)) + } + p.Outputf("Host: %s\n", utils.PtrString(resp.Raw.Credentials.Host)) + p.Outputf("Port: %s\n", utils.PtrString(resp.Raw.Credentials.Port)) } - p.Outputf("Host: %s\n", *resp.Raw.Credentials.Host) - p.Outputf("Port: %d\n", *resp.Raw.Credentials.Port) - p.Outputf("URI: %s\n", *resp.Uri) + p.Outputf("URI: %s\n", utils.PtrString(resp.Uri)) return nil } } diff --git a/internal/cmd/redis/credentials/describe/describe.go b/internal/cmd/redis/credentials/describe/describe.go index 48ec11a7c..238b67bc5 100644 --- a/internal/cmd/redis/credentials/describe/describe.go +++ b/internal/cmd/redis/credentials/describe/describe.go @@ -134,14 +134,15 @@ func outputResult(p *print.Printer, outputFormat string, credentials *redis.Cred table.AddRow("ID", *credentials.Id) table.AddSeparator() // The username field cannot be set by the user so we only display it if it's not returned empty - username := *credentials.Raw.Credentials.Username - if username != "" { - table.AddRow("USERNAME", *credentials.Raw.Credentials.Username) + if credentials.HasRaw() && credentials.Raw.Credentials != nil { + if username := credentials.Raw.Credentials.Username; username != nil && *username != "" { + table.AddRow("USERNAME", *username) + table.AddSeparator() + } + table.AddRow("PASSWORD", utils.PtrString(credentials.Raw.Credentials.Password)) table.AddSeparator() + table.AddRow("URI", utils.PtrString(credentials.Raw.Credentials.Uri)) } - table.AddRow("PASSWORD", *credentials.Raw.Credentials.Password) - table.AddSeparator() - table.AddRow("URI", *credentials.Raw.Credentials.Uri) err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) diff --git a/internal/cmd/redis/credentials/list/list.go b/internal/cmd/redis/credentials/list/list.go index 8ec94d500..78be560f1 100644 --- a/internal/cmd/redis/credentials/list/list.go +++ b/internal/cmd/redis/credentials/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" redisUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/redis" ) @@ -157,7 +157,7 @@ func outputResult(p *print.Printer, outputFormat string, credentials []redis.Cre table.SetHeader("ID") for i := range credentials { c := credentials[i] - table.AddRow(*c.Id) + table.AddRow(utils.PtrString(c.Id)) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/redis/instance/describe/describe.go b/internal/cmd/redis/instance/describe/describe.go index b89ac51f1..1b41c20d4 100644 --- a/internal/cmd/redis/instance/describe/describe.go +++ b/internal/cmd/redis/instance/describe/describe.go @@ -119,15 +119,15 @@ func outputResult(p *print.Printer, outputFormat string, instance *redis.Instanc return nil default: table := tables.NewTable() - table.AddRow("ID", *instance.InstanceId) + table.AddRow("ID", utils.PtrString(instance.InstanceId)) table.AddSeparator() - table.AddRow("NAME", *instance.Name) + table.AddRow("NAME", utils.PtrString(instance.Name)) table.AddSeparator() - table.AddRow("LAST OPERATION TYPE", *instance.LastOperation.Type) + table.AddRow("LAST OPERATION TYPE", utils.PtrString(instance.LastOperation.Type)) table.AddSeparator() - table.AddRow("LAST OPERATION STATE", *instance.LastOperation.State) + table.AddRow("LAST OPERATION STATE", utils.PtrString(instance.LastOperation.State)) table.AddSeparator() - table.AddRow("PLAN ID", *instance.PlanId) + table.AddRow("PLAN ID", utils.PtrString(instance.PlanId)) // Only show ACL if it's present and not empty acl := (*instance.Parameters)[aclParameterKey] aclStr, ok := acl.(string) diff --git a/internal/cmd/redis/instance/list/list.go b/internal/cmd/redis/instance/list/list.go index de9db7f81..2eff0bf8c 100644 --- a/internal/cmd/redis/instance/list/list.go +++ b/internal/cmd/redis/instance/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/redis" ) @@ -152,7 +152,12 @@ func outputResult(p *print.Printer, outputFormat string, instances []redis.Insta table.SetHeader("ID", "NAME", "LAST OPERATION TYPE", "LAST OPERATION STATE") for i := range instances { instance := instances[i] - table.AddRow(*instance.InstanceId, *instance.Name, *instance.LastOperation.Type, *instance.LastOperation.State) + table.AddRow( + utils.PtrString(instance.InstanceId), + utils.PtrString(instance.Name), + utils.PtrString(instance.LastOperation.Type), + utils.PtrString(instance.LastOperation.State), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/redis/plans/plans.go b/internal/cmd/redis/plans/plans.go index 564fb75e5..ef94c2a12 100644 --- a/internal/cmd/redis/plans/plans.go +++ b/internal/cmd/redis/plans/plans.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/redis" ) @@ -154,7 +154,13 @@ func outputResult(p *print.Printer, outputFormat string, plans []redis.Offering) o := plans[i] for j := range *o.Plans { plan := (*o.Plans)[j] - table.AddRow(*o.Name, *o.Version, *plan.Id, *plan.Name, *plan.Description) + table.AddRow( + utils.PtrString(o.Name), + utils.PtrString(o.Version), + utils.PtrString(plan.Id), + utils.PtrString(plan.Name), + utils.PtrString(plan.Description), + ) } table.AddSeparator() } diff --git a/internal/cmd/secrets-manager/instance/describe/describe.go b/internal/cmd/secrets-manager/instance/describe/describe.go index e299138de..416717ef1 100644 --- a/internal/cmd/secrets-manager/instance/describe/describe.go +++ b/internal/cmd/secrets-manager/instance/describe/describe.go @@ -135,17 +135,17 @@ func outputResult(p *print.Printer, outputFormat string, instance *secretsmanage return nil default: table := tables.NewTable() - table.AddRow("ID", *instance.Id) + table.AddRow("ID", utils.PtrString(instance.Id)) table.AddSeparator() - table.AddRow("NAME", *instance.Name) + table.AddRow("NAME", utils.PtrString(instance.Name)) table.AddSeparator() - table.AddRow("STATE", *instance.State) + table.AddRow("STATE", utils.PtrString(instance.State)) table.AddSeparator() - table.AddRow("SECRETS", *instance.SecretCount) + table.AddRow("SECRETS", utils.PtrString(instance.SecretCount)) table.AddSeparator() - table.AddRow("ENGINE", *instance.SecretsEngine) + table.AddRow("ENGINE", utils.PtrString(instance.SecretsEngine)) table.AddSeparator() - table.AddRow("CREATION DATE", *instance.CreationStartDate) + table.AddRow("CREATION DATE", utils.PtrString(instance.CreationStartDate)) table.AddSeparator() // Only show ACL if it's present and not empty if aclList != nil && aclList.Acls != nil && len(*aclList.Acls) > 0 { diff --git a/internal/cmd/secrets-manager/instance/list/list.go b/internal/cmd/secrets-manager/instance/list/list.go index 952ca13d0..a207cc98d 100644 --- a/internal/cmd/secrets-manager/instance/list/list.go +++ b/internal/cmd/secrets-manager/instance/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,9 +16,8 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/secretsmanager" - - "github.com/spf13/cobra" ) const ( @@ -153,7 +153,12 @@ func outputResult(p *print.Printer, outputFormat string, instances []secretsmana table.SetHeader("ID", "NAME", "STATE", "SECRETS") for i := range instances { instance := instances[i] - table.AddRow(*instance.Id, *instance.Name, *instance.State, *instance.SecretCount) + table.AddRow( + utils.PtrString(instance.Id), + utils.PtrString(instance.Name), + utils.PtrString(instance.State), + utils.PtrString(instance.SecretCount), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/secrets-manager/user/create/create.go b/internal/cmd/secrets-manager/user/create/create.go index 5506ea3d7..6143b7d98 100644 --- a/internal/cmd/secrets-manager/user/create/create.go +++ b/internal/cmd/secrets-manager/user/create/create.go @@ -156,11 +156,11 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res return nil default: - p.Outputf("Created user for instance %q. User ID: %s\n\n", instanceLabel, *resp.Id) - p.Outputf("Username: %s\n", *resp.Username) - p.Outputf("Password: %s\n", *resp.Password) - p.Outputf("Description: %s\n", *resp.Description) - p.Outputf("Write Access: %t\n", *resp.Write) + p.Outputf("Created user for instance %q. User ID: %s\n\n", instanceLabel, utils.PtrString(resp.Id)) + p.Outputf("Username: %s\n", utils.PtrString(resp.Username)) + p.Outputf("Password: %s\n", utils.PtrString(resp.Password)) + p.Outputf("Description: %s\n", utils.PtrString(resp.Description)) + p.Outputf("Write Access: %s\n", utils.PtrString(resp.Write)) return nil } diff --git a/internal/cmd/secrets-manager/user/describe/describe.go b/internal/cmd/secrets-manager/user/describe/describe.go index 35b8f927f..f93e19a24 100644 --- a/internal/cmd/secrets-manager/user/describe/describe.go +++ b/internal/cmd/secrets-manager/user/describe/describe.go @@ -133,9 +133,9 @@ func outputResult(p *print.Printer, outputFormat string, user secretsmanager.Use return nil default: table := tables.NewTable() - table.AddRow("ID", *user.Id) + table.AddRow("ID", utils.PtrString(user.Id)) table.AddSeparator() - table.AddRow("USERNAME", *user.Username) + table.AddRow("USERNAME", utils.PtrString(user.Username)) table.AddSeparator() if user.Description != nil && *user.Description != "" { table.AddRow("DESCRIPTION", *user.Description) @@ -145,7 +145,7 @@ func outputResult(p *print.Printer, outputFormat string, user secretsmanager.Use table.AddRow("PASSWORD", *user.Password) table.AddSeparator() } - table.AddRow("WRITE ACCESS", *user.Write) + table.AddRow("WRITE ACCESS", utils.PtrString(user.Write)) err := table.Display(p) if err != nil { diff --git a/internal/cmd/secrets-manager/user/list/list.go b/internal/cmd/secrets-manager/user/list/list.go index a4feee550..ad0bc0e67 100644 --- a/internal/cmd/secrets-manager/user/list/list.go +++ b/internal/cmd/secrets-manager/user/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/client" secretsManagerUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/secretsmanager" ) @@ -160,7 +160,12 @@ func outputResult(p *print.Printer, outputFormat string, users []secretsmanager. table.SetHeader("ID", "USERNAME", "DESCRIPTION", "WRITE ACCESS") for i := range users { user := users[i] - table.AddRow(*user.Id, *user.Username, *user.Description, *user.Write) + table.AddRow( + utils.PtrString(user.Id), + utils.PtrString(user.Username), + utils.PtrString(user.Description), + utils.PtrString(user.Write), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/service-account/create/create.go b/internal/cmd/service-account/create/create.go index d4aa6b026..3faec270c 100644 --- a/internal/cmd/service-account/create/create.go +++ b/internal/cmd/service-account/create/create.go @@ -14,6 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount" @@ -137,7 +138,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, serv return nil default: - p.Outputf("Created service account for project %q. Email: %s\n", projectLabel, *serviceAccount.Email) + p.Outputf("Created service account for project %q. Email: %s\n", projectLabel, utils.PtrString(serviceAccount.Email)) return nil } } diff --git a/internal/cmd/service-account/key/list/list.go b/internal/cmd/service-account/key/list/list.go index 5d9b1186e..13040757d 100644 --- a/internal/cmd/service-account/key/list/list.go +++ b/internal/cmd/service-account/key/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -14,8 +15,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount" ) @@ -166,7 +166,12 @@ func outputResult(p *print.Printer, outputFormat string, keys []serviceaccount.S if k.ValidUntil != nil { validUntil = k.ValidUntil.String() } - table.AddRow(*k.Id, *k.Active, *k.CreatedAt, validUntil) + table.AddRow( + utils.PtrString(k.Id), + utils.PtrString(k.Active), + utils.PtrString(k.CreatedAt), + validUntil, + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/service-account/list/list.go b/internal/cmd/service-account/list/list.go index 8dc2e178d..e3e6f3b83 100644 --- a/internal/cmd/service-account/list/list.go +++ b/internal/cmd/service-account/list/list.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount" ) @@ -142,7 +142,10 @@ func outputResult(p *print.Printer, outputFormat string, serviceAccounts []servi table.SetHeader("ID", "EMAIL") for i := range serviceAccounts { account := serviceAccounts[i] - table.AddRow(*account.Id, *account.Email) + table.AddRow( + utils.PtrString(account.Id), + utils.PtrString(account.Email), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/service-account/token/create/create.go b/internal/cmd/service-account/token/create/create.go index 97c08dbbf..12e0ce6fa 100644 --- a/internal/cmd/service-account/token/create/create.go +++ b/internal/cmd/service-account/token/create/create.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -13,8 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount" ) @@ -161,9 +161,9 @@ func outputResult(p *print.Printer, model *inputModel, token *serviceaccount.Acc return nil default: - p.Outputf("Created access token for service account %s. Token ID: %s\n\n", model.ServiceAccountEmail, *token.Id) - p.Outputf("Valid until: %s\n", *token.ValidUntil) - p.Outputf("Token: %s\n", *token.Token) + p.Outputf("Created access token for service account %s. Token ID: %s\n\n", model.ServiceAccountEmail, utils.PtrString(token.Id)) + p.Outputf("Valid until: %s\n", utils.PtrString(token.ValidUntil)) + p.Outputf("Token: %s\n", utils.PtrString(token.Token)) return nil } } diff --git a/internal/cmd/service-account/token/list/list.go b/internal/cmd/service-account/token/list/list.go index 3bb6aa2bb..e9395d668 100644 --- a/internal/cmd/service-account/token/list/list.go +++ b/internal/cmd/service-account/token/list/list.go @@ -14,6 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount" @@ -166,7 +167,12 @@ func outputResult(p *print.Printer, outputFormat string, tokensMetadata []servic table.SetHeader("ID", "ACTIVE", "CREATED_AT", "VALID_UNTIL") for i := range tokensMetadata { t := tokensMetadata[i] - table.AddRow(*t.Id, *t.Active, *t.CreatedAt, *t.ValidUntil) + table.AddRow( + utils.PtrString(t.Id), + utils.PtrString(t.Active), + utils.PtrString(t.CreatedAt), + utils.PtrString(t.ValidUntil), + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/ske/cluster/create/create.go b/internal/cmd/ske/cluster/create/create.go index 31fad09f4..cb5981d52 100644 --- a/internal/cmd/ske/cluster/create/create.go +++ b/internal/cmd/ske/cluster/create/create.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -18,8 +19,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/ske" "github.com/stackitcloud/stackit-sdk-go/services/ske/wait" ) @@ -220,7 +220,7 @@ func outputResult(p *print.Printer, model *inputModel, projectLabel string, resp if model.Async { operationState = "Triggered creation of" } - p.Outputf("%s cluster for project %q. Cluster name: %s\n", operationState, projectLabel, *resp.Name) + p.Outputf("%s cluster for project %q. Cluster name: %s\n", operationState, projectLabel, utils.PtrString(resp.Name)) return nil } } diff --git a/internal/cmd/ske/cluster/describe/describe.go b/internal/cmd/ske/cluster/describe/describe.go index 75a432bdb..5a4b4ec0e 100644 --- a/internal/cmd/ske/cluster/describe/describe.go +++ b/internal/cmd/ske/cluster/describe/describe.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -13,8 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/ske" ) @@ -121,11 +121,11 @@ func outputResult(p *print.Printer, outputFormat string, cluster *ske.Cluster) e } table := tables.NewTable() - table.AddRow("NAME", *cluster.Name) + table.AddRow("NAME", utils.PtrString(cluster.Name)) table.AddSeparator() - table.AddRow("STATE", *cluster.Status.Aggregated) + table.AddRow("STATE", utils.PtrString(cluster.Status.Aggregated)) table.AddSeparator() - table.AddRow("VERSION", *cluster.Kubernetes.Version) + table.AddRow("VERSION", utils.PtrString(cluster.Kubernetes.Version)) table.AddSeparator() table.AddRow("ACL", acl) err := table.Display(p) diff --git a/internal/cmd/ske/cluster/list/list.go b/internal/cmd/ske/cluster/list/list.go index 834b2ea38..785f645c1 100644 --- a/internal/cmd/ske/cluster/list/list.go +++ b/internal/cmd/ske/cluster/list/list.go @@ -17,6 +17,7 @@ import ( serviceEnablementUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-enablement/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/ske" @@ -173,7 +174,13 @@ func outputResult(p *print.Printer, outputFormat string, clusters []ske.Cluster) if c.Extensions != nil && c.Extensions.Argus != nil && *c.Extensions.Argus.Enabled { monitoring = "Enabled" } - table.AddRow(*c.Name, *c.Status.Aggregated, *c.Kubernetes.Version, len(*c.Nodepools), monitoring) + table.AddRow( + utils.PtrString(c.Name), + utils.PtrString(c.Status.Aggregated), + utils.PtrString(c.Kubernetes.Version), + len(*c.Nodepools), + monitoring, + ) } err := table.Display(p) if err != nil { diff --git a/internal/cmd/ske/describe/describe.go b/internal/cmd/ske/describe/describe.go index 3f54a607d..53d9dd848 100644 --- a/internal/cmd/ske/describe/describe.go +++ b/internal/cmd/ske/describe/describe.go @@ -6,17 +6,17 @@ import ( "fmt" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-enablement/client" - "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-enablement/utils" + skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-enablement/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/serviceenablement" - - "github.com/spf13/cobra" ) type inputModel struct { @@ -82,7 +82,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { } func buildRequest(ctx context.Context, model *inputModel, apiClient *serviceenablement.APIClient) serviceenablement.ApiGetServiceStatusRequest { - req := apiClient.GetServiceStatus(ctx, model.ProjectId, utils.SKEServiceId) + req := apiClient.GetServiceStatus(ctx, model.ProjectId, skeUtils.SKEServiceId) return req } @@ -108,7 +108,7 @@ func outputResult(p *print.Printer, outputFormat string, project *serviceenablem table := tables.NewTable() table.AddRow("ID", projectId) table.AddSeparator() - table.AddRow("STATE", *project.State) + table.AddRow("STATE", utils.PtrString(project.State)) err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) diff --git a/internal/cmd/ske/kubeconfig/create/create.go b/internal/cmd/ske/kubeconfig/create/create.go index 4d2549e04..adc74b0e5 100644 --- a/internal/cmd/ske/kubeconfig/create/create.go +++ b/internal/cmd/ske/kubeconfig/create/create.go @@ -14,6 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/ske" @@ -274,7 +275,7 @@ func outputResult(p *print.Printer, model *inputModel, kubeconfigPath string, re default: var expiration string if respKubeconfig != nil { - expiration = fmt.Sprintf(", with expiration date %v (UTC)", *respKubeconfig.ExpirationTimestamp) + expiration = fmt.Sprintf(", with expiration date %v (UTC)", utils.ConvertTimePToDateTimeString(respKubeconfig.ExpirationTimestamp)) } p.Outputf("Updated kubeconfig file for cluster %s in %q%s\n", model.ClusterName, kubeconfigPath, expiration) diff --git a/internal/cmd/ske/options/options.go b/internal/cmd/ske/options/options.go index 51a8abb93..e8ad07eea 100644 --- a/internal/cmd/ske/options/options.go +++ b/internal/cmd/ske/options/options.go @@ -8,6 +8,7 @@ import ( "time" "github.com/goccy/go-yaml" + "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" @@ -15,8 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" - - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/stackitcloud/stackit-sdk-go/services/ske" ) @@ -241,7 +241,11 @@ func buildKubernetesVersionsTable(resp *ske.ProviderOptions) (tables.Table, erro if v.ExpirationDate != nil { expirationDate = v.ExpirationDate.Format(time.RFC3339) } - table.AddRow(*v.Version, *v.State, expirationDate, string(featureGate)) + table.AddRow( + utils.PtrString(v.Version), + utils.PtrString(v.State), + expirationDate, + string(featureGate)) } return table, nil } @@ -268,7 +272,13 @@ func buildMachineImagesTable(resp *ske.ProviderOptions) tables.Table { if version.ExpirationDate != nil { expirationDate = version.ExpirationDate.Format(time.RFC3339) } - table.AddRow(*image.Name, *version.Version, *version.State, expirationDate, criNamesString) + table.AddRow( + utils.PtrString(image.Name), + utils.PtrString(version.Version), + utils.PtrString(version.State), + expirationDate, + criNamesString, + ) } } table.EnableAutoMergeOnColumns(1) @@ -283,7 +293,11 @@ func buildMachineTypesTable(resp *ske.ProviderOptions) tables.Table { table.SetHeader("TYPE", "CPU", "MEMORY") for i := range types { t := types[i] - table.AddRow(*t.Name, *t.Cpu, *t.Memory) + table.AddRow( + utils.PtrString(t.Name), + utils.PtrString(t.Cpu), + utils.PtrString(t.Memory), + ) } return table } @@ -296,7 +310,7 @@ func buildVolumeTypesTable(resp *ske.ProviderOptions) tables.Table { table.SetHeader("TYPE") for i := range types { z := types[i] - table.AddRow(*z.Name) + table.AddRow(utils.PtrString(z.Name)) } return table } diff --git a/internal/pkg/utils/strings.go b/internal/pkg/utils/strings.go index 6c33cfc82..36cfda139 100644 --- a/internal/pkg/utils/strings.go +++ b/internal/pkg/utils/strings.go @@ -24,3 +24,12 @@ func JoinStringKeysPtr(m map[string]any, sep string) string { } return JoinStringKeys(m, sep) } + +// JoinStringPtr concatenates the strings of a string slice pointer, each separatore by the +// [sep] string. +func JoinStringPtr(vals *[]string, sep string) string { + if vals == nil || len(*vals) == 0 { + return "" + } + return strings.Join(*vals, sep) +} diff --git a/internal/pkg/utils/utils.go b/internal/pkg/utils/utils.go index 1b4a4ad5e..e8fea5884 100644 --- a/internal/pkg/utils/utils.go +++ b/internal/pkg/utils/utils.go @@ -7,6 +7,7 @@ import ( "time" "github.com/google/uuid" + "github.com/inhies/go-bytesize" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/stackitcloud/stackit-cli/internal/pkg/config" @@ -89,3 +90,20 @@ func ConvertTimePToDateTimeString(t *time.Time) string { } return t.Format(time.DateTime) } + +// PtrStringDefault return the value of a pointer [v] as string. If the pointer is nil, it returns the [defaultValue]. +func PtrStringDefault[T any](v *T, defaultValue string) string { + if v == nil { + return defaultValue + } + return fmt.Sprintf("%v", *v) +} + +// PtrByteSizeDefault return the value of an in64 pointer to a string representation of bytesize. If the pointer is nil, +// it returns the [defaultValue]. +func PtrByteSizeDefault(size *int64, defaultValue string) string { + if size == nil { + return defaultValue + } + return bytesize.New(float64(*size)).String() +}