Skip to content

Commit 75f7943

Browse files
committed
checked for possible nil pointers
1 parent 70f8e99 commit 75f7943

File tree

13 files changed

+256
-59
lines changed

13 files changed

+256
-59
lines changed

docs/stackit_ske_options.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ stackit ske options [flags]
4949
### SEE ALSO
5050

5151
* [stackit ske](./stackit_ske.md) - Provides functionality for SKE
52+
* [stackit ske options availability-zones](./stackit_ske_options_availability-zones.md) - Lists SKE provider options for availability-zones
53+
* [stackit ske options kubernetes-versions](./stackit_ske_options_kubernetes-versions.md) - Lists SKE provider options for kubernetes-versions
54+
* [stackit ske options machine-images](./stackit_ske_options_machine-images.md) - Lists SKE provider options for machine-images
55+
* [stackit ske options machine-types](./stackit_ske_options_machine-types.md) - Lists SKE provider options for machine-types
56+
* [stackit ske options volume-types](./stackit_ske_options_volume-types.md) - Lists SKE provider options for volume-types
5257

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit ske options availability-zones
2+
3+
Lists SKE provider options for availability-zones
4+
5+
### Synopsis
6+
7+
Lists STACKIT Kubernetes Engine (SKE) provider options for availability-zones.
8+
9+
```
10+
stackit ske options availability-zones [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List SKE options for availability-zones
17+
$ stackit ske options availability-zones
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit ske options availability-zones"
24+
```
25+
26+
### Options inherited from parent commands
27+
28+
```
29+
-y, --assume-yes If set, skips all confirmation prompts
30+
--async If set, runs the command asynchronously
31+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
32+
-p, --project-id string Project ID
33+
--region string Target region for region-specific requests
34+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options
40+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## stackit ske options kubernetes-versions
2+
3+
Lists SKE provider options for kubernetes-versions
4+
5+
### Synopsis
6+
7+
Lists STACKIT Kubernetes Engine (SKE) provider options for kubernetes-versions.
8+
9+
```
10+
stackit ske options kubernetes-versions [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List SKE options for kubernetes-versions
17+
$ stackit ske options kubernetes-versions
18+
19+
List SKE options for supported kubernetes-versions
20+
$ stackit ske options kubernetes-versions --supported
21+
```
22+
23+
### Options
24+
25+
```
26+
-h, --help Help for "stackit ske options kubernetes-versions"
27+
--supported List supported versions only
28+
```
29+
30+
### Options inherited from parent commands
31+
32+
```
33+
-y, --assume-yes If set, skips all confirmation prompts
34+
--async If set, runs the command asynchronously
35+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
36+
-p, --project-id string Project ID
37+
--region string Target region for region-specific requests
38+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
39+
```
40+
41+
### SEE ALSO
42+
43+
* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options
44+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit ske options machine-images
2+
3+
Lists SKE provider options for machine-images
4+
5+
### Synopsis
6+
7+
Lists STACKIT Kubernetes Engine (SKE) provider options for machine-images.
8+
9+
```
10+
stackit ske options machine-images [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List SKE options for machine-images
17+
$ stackit ske options machine-images
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit ske options machine-images"
24+
```
25+
26+
### Options inherited from parent commands
27+
28+
```
29+
-y, --assume-yes If set, skips all confirmation prompts
30+
--async If set, runs the command asynchronously
31+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
32+
-p, --project-id string Project ID
33+
--region string Target region for region-specific requests
34+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options
40+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit ske options machine-types
2+
3+
Lists SKE provider options for machine-types
4+
5+
### Synopsis
6+
7+
Lists STACKIT Kubernetes Engine (SKE) provider options for machine-types.
8+
9+
```
10+
stackit ske options machine-types [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List SKE options for machine-types
17+
$ stackit ske options machine-types
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit ske options machine-types"
24+
```
25+
26+
### Options inherited from parent commands
27+
28+
```
29+
-y, --assume-yes If set, skips all confirmation prompts
30+
--async If set, runs the command asynchronously
31+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
32+
-p, --project-id string Project ID
33+
--region string Target region for region-specific requests
34+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options
40+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## stackit ske options volume-types
2+
3+
Lists SKE provider options for volume-types
4+
5+
### Synopsis
6+
7+
Lists STACKIT Kubernetes Engine (SKE) provider options for volume-types.
8+
9+
```
10+
stackit ske options volume-types [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
List SKE options for volume-types
17+
$ stackit ske options volume-types
18+
```
19+
20+
### Options
21+
22+
```
23+
-h, --help Help for "stackit ske options volume-types"
24+
```
25+
26+
### Options inherited from parent commands
27+
28+
```
29+
-y, --assume-yes If set, skips all confirmation prompts
30+
--async If set, runs the command asynchronously
31+
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
32+
-p, --project-id string Project ID
33+
--region string Target region for region-specific requests
34+
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
35+
```
36+
37+
### SEE ALSO
38+
39+
* [stackit ske options](./stackit_ske_options.md) - Lists SKE provider options
40+

internal/cmd/ske/options/availability_zones/availability_zones.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
8+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
89

910
"github.com/spf13/cobra"
1011
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
@@ -17,17 +18,15 @@ import (
1718
)
1819

1920
type inputModel struct {
20-
*globalflags.GlobalFlagModel
21+
globalflags.GlobalFlagModel
2122
}
2223

2324
func NewCmd(params *types.CmdParams) *cobra.Command {
2425
cmd := &cobra.Command{
2526
Use: "availability-zones",
2627
Short: "Lists SKE provider options for availability-zones",
27-
Long: fmt.Sprintf("%s\n%s",
28-
"Lists STACKIT Kubernetes Engine (SKE) provider options for availability-zones.",
29-
),
30-
Args: args.NoArgs,
28+
Long: "Lists STACKIT Kubernetes Engine (SKE) provider options for availability-zones.",
29+
Args: args.NoArgs,
3130
Example: examples.Build(
3231
examples.NewExample(
3332
`List SKE options for availability-zones`,
@@ -63,7 +62,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
6362
globalFlags := globalflags.Parse(p, cmd)
6463

6564
model := inputModel{
66-
GlobalFlagModel: globalFlags,
65+
GlobalFlagModel: utils.PtrValue(globalFlags),
6766
}
6867

6968
p.DebugInputModel(model)
@@ -76,23 +75,20 @@ func buildRequest(ctx context.Context, apiClient *ske.APIClient, model *inputMod
7675
}
7776

7877
func outputResult(p *print.Printer, model *inputModel, options *ske.ProviderOptions) error {
79-
if model == nil || model.GlobalFlagModel == nil {
78+
if model == nil {
8079
return fmt.Errorf("model is nil")
8180
} else if options == nil {
8281
return fmt.Errorf("options is nil")
8382
}
8483

85-
options.MachineTypes = nil
86-
options.VolumeTypes = nil
87-
8884
return p.OutputResult(model.OutputFormat, options, func() error {
89-
zones := *options.AvailabilityZones
85+
zones := utils.PtrValue(options.AvailabilityZones)
9086

9187
table := tables.NewTable()
9288
table.SetHeader("ZONE")
9389
for i := range zones {
9490
z := zones[i]
95-
table.AddRow(*z.Name)
91+
table.AddRow(utils.PtrValue(z.Name))
9692
}
9793

9894
err := table.Display(p)

internal/cmd/ske/options/kubernetes_versions/kubernetes_versions.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,16 @@ const (
2525
)
2626

2727
type inputModel struct {
28-
*globalflags.GlobalFlagModel
28+
globalflags.GlobalFlagModel
2929
Supported bool
3030
}
3131

3232
func NewCmd(params *types.CmdParams) *cobra.Command {
3333
cmd := &cobra.Command{
3434
Use: "kubernetes-versions",
3535
Short: "Lists SKE provider options for kubernetes-versions",
36-
Long: fmt.Sprintf("%s\n%s",
37-
"Lists STACKIT Kubernetes Engine (SKE) provider options for kubernetes-versions.",
38-
),
39-
Args: args.NoArgs,
36+
Long: "Lists STACKIT Kubernetes Engine (SKE) provider options for kubernetes-versions.",
37+
Args: args.NoArgs,
4038
Example: examples.Build(
4139
examples.NewExample(
4240
`List SKE options for kubernetes-versions`,
@@ -80,7 +78,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
8078
globalFlags := globalflags.Parse(p, cmd)
8179

8280
model := inputModel{
83-
GlobalFlagModel: globalFlags,
81+
GlobalFlagModel: utils.PtrValue(globalFlags),
8482
Supported: flags.FlagToBoolValue(p, cmd, supportedFlag),
8583
}
8684

@@ -97,22 +95,22 @@ func buildRequest(ctx context.Context, apiClient *ske.APIClient, model *inputMod
9795
}
9896

9997
func outputResult(p *print.Printer, model *inputModel, options *ske.ProviderOptions) error {
100-
if model == nil || model.GlobalFlagModel == nil {
98+
if model == nil {
10199
return fmt.Errorf("model is nil")
102100
} else if options == nil {
103101
return fmt.Errorf("options is nil")
104102
}
105103

106104
return p.OutputResult(model.OutputFormat, options, func() error {
107-
versions := *options.KubernetesVersions
105+
versions := utils.PtrValue(options.KubernetesVersions)
108106

109107
table := tables.NewTable()
110108
table.SetHeader("VERSION", "STATE", "EXPIRATION DATE", "FEATURE GATES")
111109
for i := range versions {
112110
v := versions[i]
113-
featureGate, err := json.Marshal(*v.FeatureGates)
111+
featureGate, err := json.Marshal(utils.PtrValue(v.FeatureGates))
114112
if err != nil {
115-
return fmt.Errorf("marshal featureGates of Kubernetes version %q: %w", *v.Version, err)
113+
return fmt.Errorf("marshal featureGates of Kubernetes version %q: %w", utils.PtrValue(v.Version), err)
116114
}
117115
expirationDate := ""
118116
if v.ExpirationDate != nil {

0 commit comments

Comments
 (0)