Skip to content

Commit 10eb0b9

Browse files
committed
fix: bug in unlink logic
1 parent 0444adf commit 10eb0b9

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

cmd/app/unlink.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ package app
1717
import (
1818
"context"
1919
"fmt"
20+
"strings"
2021

2122
"github.com/slackapi/slack-cli/internal/cmdutil"
22-
"github.com/slackapi/slack-cli/internal/iostreams"
2323
"github.com/slackapi/slack-cli/internal/prompts"
2424
"github.com/slackapi/slack-cli/internal/shared"
2525
"github.com/slackapi/slack-cli/internal/shared/types"
@@ -33,6 +33,8 @@ var unlinkAppSelectPromptFunc = prompts.AppSelectPrompt
3333

3434
// NewUnlinkCommand returns a new Cobra command for unlinking apps
3535
func NewUnlinkCommand(clients *shared.ClientFactory) *cobra.Command {
36+
var unlinkedApp types.App // capture app for PostRunE
37+
3638
cmd := &cobra.Command{
3739
Use: "unlink",
3840
Short: "Remove a linked app from the project",
@@ -57,17 +59,20 @@ func NewUnlinkCommand(clients *shared.ClientFactory) *cobra.Command {
5759
},
5860
RunE: func(cmd *cobra.Command, args []string) error {
5961
ctx := cmd.Context()
60-
clients.IO.PrintTrace(ctx, slacktrace.AppUnlinkStart)
6162

6263
app, err := UnlinkCommandRunE(ctx, clients, cmd, args)
6364
if err != nil {
6465
return err
6566
}
67+
if app.AppID == "" { // user canceled
68+
return nil
69+
}
70+
unlinkedApp = app // stored for PostRunE
6671
return printUnlinkSuccess(ctx, clients, app)
6772
},
6873
PostRunE: func(cmd *cobra.Command, args []string) error {
6974
ctx := cmd.Context()
70-
clients.IO.PrintTrace(ctx, slacktrace.AppUnlinkSuccess)
75+
clients.IO.PrintTrace(ctx, slacktrace.AppUnlinkSuccess, unlinkedApp.AppID)
7176
return nil
7277
},
7378
}
@@ -76,15 +81,27 @@ func NewUnlinkCommand(clients *shared.ClientFactory) *cobra.Command {
7681

7782
// UnlinkCommandRunE executes the unlink command, prints output, and returns any errors.
7883
func UnlinkCommandRunE(ctx context.Context, clients *shared.ClientFactory, cmd *cobra.Command, args []string) (types.App, error) {
84+
clients.IO.PrintTrace(ctx, slacktrace.AppUnlinkStart)
85+
7986
// Get the app selection from the flag or prompt
8087
selection, err := unlinkAppSelectPromptFunc(ctx, clients, prompts.ShowAllEnvironments, prompts.ShowInstalledAndUninstalledApps)
8188
if err != nil {
8289
return types.App{}, err
8390
}
8491

92+
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
93+
Emoji: "unlock",
94+
Text: "App Unlink",
95+
Secondary: []string{
96+
fmt.Sprintf("App (%s) will be removed from this project", selection.App.AppID),
97+
"The app will not be deleted from Slack",
98+
fmt.Sprintf("You can re-link it later with %s", style.Commandf("app link", false)),
99+
},
100+
}))
101+
85102
// Confirm with user unless --force flag is used
86103
if !clients.Config.ForceFlag {
87-
proceed, err := confirmUnlink(ctx, clients.IO, selection)
104+
proceed, err := clients.IO.ConfirmPrompt(ctx, "Are you sure you want to unlink this app?", false)
88105
if err != nil {
89106
return types.App{}, err
90107
}
@@ -102,23 +119,8 @@ func UnlinkCommandRunE(ctx context.Context, clients *shared.ClientFactory, cmd *
102119
if err != nil {
103120
return types.App{}, err
104121
}
105-
return app, nil
106-
}
107-
108-
// confirmUnlink prompts the user to confirm unlinking the app
109-
func confirmUnlink(ctx context.Context, IO iostreams.IOStreamer, selection prompts.SelectedApp) (bool, error) {
110-
IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
111-
Emoji: "unlock",
112-
Text: "App Unlink",
113-
Secondary: []string{
114-
fmt.Sprintf("App (%s) will be removed from this project", selection.App.AppID),
115-
"The app will not be deleted from Slack",
116-
fmt.Sprintf("You can re-link it later with %s", style.Commandf("app link", false)),
117-
},
118-
}))
119122

120-
proceed, err := IO.ConfirmPrompt(ctx, "Are you sure you want to unlink this app?", false)
121-
return proceed, err
123+
return app, nil
122124
}
123125

124126
// printUnlinkSuccess displays success message after unlinking

0 commit comments

Comments
 (0)