Skip to content

Commit b1a0d39

Browse files
committed
fix: properly check error return value in upgrade command
1 parent b7ae43a commit b1a0d39

5 files changed

Lines changed: 13 additions & 11 deletions

File tree

cmd/upgrade/upgrade.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const changelogURL = "https://docs.slack.dev/changelog"
3232

3333
func NewCommand(clients *shared.ClientFactory) *cobra.Command {
3434
var autoApprove bool
35-
35+
3636
cmd := &cobra.Command{
3737
Use: "upgrade",
3838
Aliases: []string{"update"},
@@ -52,9 +52,9 @@ func NewCommand(clients *shared.ClientFactory) *cobra.Command {
5252
return checkForUpdatesFunc(clients, cmd, autoApprove)
5353
},
5454
}
55-
55+
5656
cmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "automatically approve and install updates without prompting")
57-
57+
5858
return cmd
5959
}
6060

@@ -79,7 +79,9 @@ func checkForUpdates(clients *shared.ClientFactory, cmd *cobra.Command, autoAppr
7979
if updateNotification.HasUpdate() {
8080
if autoApprove {
8181
// Automatically install updates without prompting when auto-approve flag is set
82-
updateNotification.InstallUpdatesWithoutPrompt(cmd)
82+
if err := updateNotification.InstallUpdatesWithoutPrompt(cmd); err != nil {
83+
return err
84+
}
8385
return nil
8486
}
8587
return nil

cmd/upgrade/upgrade_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ func TestUpgradeCommand(t *testing.T) {
6161
cmd = NewCommand(clients)
6262
testutil.MockCmdIO(clients.IO, cmd)
6363
cmd.SetArgs([]string{"--auto-approve"})
64-
64+
6565
updatePkgMock = new(UpdatePkgMock)
6666
checkForUpdatesFunc = updatePkgMock.CheckForUpdates
6767
updatePkgMock.On("CheckForUpdates", mock.Anything, mock.Anything, true).Return(nil)
68-
68+
6969
err = cmd.ExecuteContext(ctx)
7070
if err != nil {
7171
assert.Fail(t, "cmd.Upgrade with auto-approve had unexpected error")

internal/update/cli.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ func (c *CLIDependency) PrintUpdateNotification(cmd *cobra.Command) (bool, error
9393
"\n To manually update, visit the download page:\n %s\n\n",
9494
style.CommandText("https://tools.slack.dev/slack-cli"),
9595
)
96-
96+
9797
// Check for auto-approve from upgrade command
9898
if cmd.Name() == "upgrade" && cmd.Flags().Changed("auto-approve") {
9999
autoApprove, _ := cmd.Flags().GetBool("auto-approve")
100100
if autoApprove {
101-
return true, nil
101+
return true, nil
102102
}
103103
}
104-
104+
105105
selfUpdatePrompt := fmt.Sprintf("%sDo you want to auto-update to the latest version now?", style.Emoji("rocket"))
106106
return c.clients.IO.ConfirmPrompt(ctx, selfUpdatePrompt, false)
107107
}

internal/update/sdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func (c *SDKDependency) PrintUpdateNotification(cmd *cobra.Command) (bool, error
326326
return true, nil
327327
}
328328
}
329-
329+
330330
autoUpdatePrompt := fmt.Sprintf("%sDo you want to auto-update to the latest versions now?", style.Emoji("rocket"))
331331
return c.clients.IO.ConfirmPrompt(ctx, autoUpdatePrompt, false)
332332
}

internal/update/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func (u *UpdateNotification) InstallUpdatesWithoutPrompt(cmd *cobra.Command) err
270270
if err != nil {
271271
return err
272272
}
273-
273+
274274
// Install the update without prompting
275275
cmd.Printf("%s Installing update automatically...\n", style.Styler().Green("✓").String())
276276
if err := dependency.InstallUpdate(ctx); err != nil {

0 commit comments

Comments
 (0)