Skip to content

Commit 5b29ad4

Browse files
authored
Fix panic reading empty args slice (#1163)
Signed-off-by: Borja Clemente <[email protected]>
1 parent 9a0282f commit 5b29ad4

File tree

9 files changed

+33
-11
lines changed

9 files changed

+33
-11
lines changed

cli/pkg/kctrl/cmd/package/available/get.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ func (o *GetOptions) Run(args []string) error {
7777
var pkgName, pkgVersion string
7878

7979
if o.pkgCmdTreeOpts.PositionalArgs {
80-
o.Name = args[0]
80+
if len(args) > 0 {
81+
o.Name = args[0]
82+
}
8183
}
8284

8385
if len(o.Name) == 0 {

cli/pkg/kctrl/cmd/package/available/list.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ func NewListCmd(o *ListOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Comman
8282

8383
func (o *ListOptions) Run(args []string) error {
8484
if o.pkgCmdTreeOpts.PositionalArgs && len(args) > 0 {
85-
o.Name = args[0]
85+
if len(args) > 0 {
86+
o.Name = args[0]
87+
}
8688
}
8789

8890
if o.Summary && o.Name == "" {

cli/pkg/kctrl/cmd/package/installed/create_or_update.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ func (o *CreateOrUpdateOptions) RunCreate(args []string) error {
207207
o.createdAnnotations = NewCreatedResourceAnnotations(o.Name, o.NamespaceFlags.Name)
208208

209209
if o.pkgCmdTreeOpts.PositionalArgs {
210-
o.Name = args[0]
210+
if len(args) > 0 {
211+
o.Name = args[0]
212+
}
211213
}
212214

213215
if len(o.Name) == 0 {
@@ -312,7 +314,9 @@ func (o *CreateOrUpdateOptions) create(client kubernetes.Interface, kcClient kcc
312314

313315
func (o *CreateOrUpdateOptions) RunUpdate(args []string) error {
314316
if o.pkgCmdTreeOpts.PositionalArgs {
315-
o.Name = args[0]
317+
if len(args) > 0 {
318+
o.Name = args[0]
319+
}
316320
}
317321

318322
if len(o.Name) == 0 {

cli/pkg/kctrl/cmd/package/installed/delete.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ func NewDeleteCmd(o *DeleteOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Co
8282

8383
func (o *DeleteOptions) Run(args []string) error {
8484
if o.pkgCmdTreeOpts.PositionalArgs {
85-
o.Name = args[0]
85+
if len(args) > 0 {
86+
o.Name = args[0]
87+
}
8688
}
8789

8890
if len(o.Name) == 0 {

cli/pkg/kctrl/cmd/package/installed/get.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ func NewGetCmd(o *GetOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Command
7676

7777
func (o *GetOptions) Run(args []string) error {
7878
if o.pkgCmdTreeOpts.PositionalArgs {
79-
o.Name = args[0]
79+
if len(args) > 0 {
80+
o.Name = args[0]
81+
}
8082
}
8183

8284
if len(o.Name) == 0 {

cli/pkg/kctrl/cmd/package/installed/pause_or_kick.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ func NewKickCmd(o *PauseOrKickOptions, flagsFactory cmdcore.FlagsFactory) *cobra
103103

104104
func (o *PauseOrKickOptions) Pause(args []string) error {
105105
if o.pkgCmdTreeOpts.PositionalArgs {
106-
o.Name = args[0]
106+
if len(args) > 0 {
107+
o.Name = args[0]
108+
}
107109
}
108110

109111
if len(o.Name) == 0 {
@@ -132,7 +134,9 @@ func (o *PauseOrKickOptions) Pause(args []string) error {
132134

133135
func (o *PauseOrKickOptions) Kick(args []string) error {
134136
if o.pkgCmdTreeOpts.PositionalArgs {
135-
o.Name = args[0]
137+
if len(args) > 0 {
138+
o.Name = args[0]
139+
}
136140
}
137141

138142
if len(o.Name) == 0 {

cli/pkg/kctrl/cmd/package/repository/add_or_update.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ func NewUpdateCmd(o *AddOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *cob
128128

129129
func (o *AddOrUpdateOptions) Run(args []string) error {
130130
if o.pkgCmdTreeOpts.PositionalArgs {
131-
o.Name = args[0]
131+
if len(args) > 0 {
132+
o.Name = args[0]
133+
}
132134
}
133135

134136
if len(o.Name) == 0 {

cli/pkg/kctrl/cmd/package/repository/delete.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ func NewDeleteCmd(o *DeleteOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Co
6969

7070
func (o *DeleteOptions) Run(args []string) error {
7171
if o.pkgCmdTreeOpts.PositionalArgs {
72-
o.Name = args[0]
72+
if len(args) > 0 {
73+
o.Name = args[0]
74+
}
7375
}
7476

7577
if len(o.Name) == 0 {

cli/pkg/kctrl/cmd/package/repository/get.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ func NewGetCmd(o *GetOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Command
5959

6060
func (o *GetOptions) Run(args []string) error {
6161
if o.pkgCmdTreeOpts.PositionalArgs {
62-
o.Name = args[0]
62+
if len(args) > 0 {
63+
o.Name = args[0]
64+
}
6365
}
6466

6567
if len(o.Name) == 0 {

0 commit comments

Comments
 (0)