Skip to content

Commit 62770ba

Browse files
authored
feat(experiment): use charm prompt with login (#349)
1 parent 4fb7b4f commit 62770ba

6 files changed

Lines changed: 162 additions & 46 deletions

File tree

cmd/auth/login.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"context"
1919
"fmt"
2020

21+
"github.com/slackapi/slack-cli/internal/config"
22+
"github.com/slackapi/slack-cli/internal/experiment"
2123
"github.com/slackapi/slack-cli/internal/iostreams"
2224
authpkg "github.com/slackapi/slack-cli/internal/pkg/auth"
2325
"github.com/slackapi/slack-cli/internal/shared"
@@ -109,7 +111,7 @@ func RunLoginCommand(clients *shared.ClientFactory, cmd *cobra.Command) (types.S
109111
return types.SlackAuth{}, err
110112
}
111113
if selectedAuth.Token != "" {
112-
printAuthSuccess(cmd, clients.IO, credentialsPath, selectedAuth.Token)
114+
printAuthSuccess(cmd, clients.Config, clients.IO, credentialsPath, selectedAuth.Token)
113115
printAuthNextSteps(ctx, clients)
114116
}
115117
return selectedAuth, err
@@ -119,14 +121,14 @@ func RunLoginCommand(clients *shared.ClientFactory, cmd *cobra.Command) (types.S
119121
if err != nil {
120122
return types.SlackAuth{}, err
121123
} else {
122-
printAuthSuccess(cmd, clients.IO, credentialsPath, selectedAuth.Token)
124+
printAuthSuccess(cmd, clients.Config, clients.IO, credentialsPath, selectedAuth.Token)
123125
printAuthNextSteps(ctx, clients)
124126
}
125127

126128
return selectedAuth, nil
127129
}
128130

129-
func printAuthSuccess(cmd *cobra.Command, IO iostreams.IOStreamer, credentialsPath string, token string) {
131+
func printAuthSuccess(cmd *cobra.Command, config *config.Config, IO iostreams.IOStreamer, credentialsPath string, token string) {
130132
ctx := cmd.Context()
131133

132134
var secondaryLog string
@@ -136,7 +138,13 @@ func printAuthSuccess(cmd *cobra.Command, IO iostreams.IOStreamer, credentialsPa
136138
secondaryLog = fmt.Sprintf("Service token:\n\n %s\n\nMake sure to copy the token now and save it safely.", token)
137139
}
138140

139-
IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
141+
// The legacy prompt leaves no blank line before the success message, so
142+
// print one here. The Charm-based prompt already handles spacing.
143+
if !config.WithExperimentOn(experiment.Charm) {
144+
IO.PrintInfo(ctx, false, "")
145+
}
146+
147+
IO.PrintInfo(ctx, false, "%s", style.Sectionf(style.TextSection{
140148
Emoji: "key",
141149
Text: "You've successfully authenticated!",
142150
Secondary: []string{secondaryLog},

cmd/root.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323
"syscall"
2424

25+
"github.com/charmbracelet/huh"
2526
"github.com/slackapi/slack-cli/cmd/app"
2627
"github.com/slackapi/slack-cli/cmd/auth"
2728
"github.com/slackapi/slack-cli/cmd/collaborators"
@@ -144,6 +145,10 @@ func Init(ctx context.Context) (*cobra.Command, *shared.ClientFactory) {
144145
// updateNotification will check for an update in the background and print a message after the command runs
145146
var updateNotification *update.UpdateNotification
146147

148+
// Override huh's default user abort error with a Slack CLI error so that
149+
// cancelled prompts are handled consistently as process interruptions.
150+
huh.ErrUserAborted = slackerror.New(slackerror.ErrProcessInterrupted)
151+
147152
clients = shared.NewClientFactory(shared.SetVersion(version.Raw()))
148153
rootCmd := NewRootCommand(clients, updateNotification)
149154

go.mod

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.26.0
55
require (
66
github.com/AlecAivazis/survey/v2 v2.3.7
77
github.com/briandowns/spinner v1.23.2
8+
github.com/charmbracelet/huh v0.8.0
89
github.com/cli/safeexec v1.0.1
910
github.com/google/uuid v1.6.0
1011
github.com/gorilla/websocket v1.5.3
@@ -34,26 +35,49 @@ require (
3435
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
3536
github.com/Microsoft/go-winio v0.6.2 // indirect
3637
github.com/ProtonMail/go-crypto v1.3.0 // indirect
38+
github.com/atotto/clipboard v0.1.4 // indirect
39+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
40+
github.com/catppuccin/go v0.3.0 // indirect
3741
github.com/chainguard-dev/git-urls v1.0.2 // indirect
38-
github.com/cloudflare/circl v1.6.1 // indirect
39-
github.com/creack/pty v1.1.18 // indirect
40-
github.com/cyphar/filepath-securejoin v0.5.0 // indirect
42+
github.com/charmbracelet/bubbles v1.0.0 // indirect
43+
github.com/charmbracelet/bubbletea v1.3.10 // indirect
44+
github.com/charmbracelet/colorprofile v0.4.2 // indirect
45+
github.com/charmbracelet/lipgloss v1.1.0 // indirect
46+
github.com/charmbracelet/x/ansi v0.11.6 // indirect
47+
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
48+
github.com/charmbracelet/x/exp/strings v0.1.0 // indirect
49+
github.com/charmbracelet/x/term v0.2.2 // indirect
50+
github.com/clipperhouse/displaywidth v0.11.0 // indirect
51+
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
52+
github.com/cloudflare/circl v1.6.3 // indirect
53+
github.com/cyphar/filepath-securejoin v0.6.1 // indirect
54+
github.com/dustin/go-humanize v1.0.1 // indirect
4155
github.com/emirpasic/gods v1.18.1 // indirect
56+
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
4257
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
43-
github.com/go-git/go-billy/v5 v5.6.2 // indirect
58+
github.com/go-git/go-billy/v5 v5.7.0 // indirect
4459
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
4560
github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02 // indirect
4661
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
47-
github.com/kevinburke/ssh_config v1.4.0 // indirect
62+
github.com/kevinburke/ssh_config v1.6.0 // indirect
4863
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
64+
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
65+
github.com/mattn/go-localereader v0.0.1 // indirect
66+
github.com/mattn/go-runewidth v0.0.20 // indirect
67+
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
68+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
69+
github.com/muesli/cancelreader v0.2.2 // indirect
70+
github.com/muesli/termenv v0.16.0 // indirect
4971
github.com/pjbgf/sha1cd v0.5.0 // indirect
72+
github.com/rivo/uniseg v0.4.7 // indirect
5073
github.com/sergi/go-diff v1.4.0 // indirect
5174
github.com/skeema/knownhosts v1.3.2 // indirect
5275
github.com/xanzy/ssh-agent v0.3.3 // indirect
53-
golang.org/x/crypto v0.45.0 // indirect
54-
golang.org/x/net v0.47.0 // indirect
76+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
77+
golang.org/x/crypto v0.48.0 // indirect
78+
golang.org/x/net v0.50.0 // indirect
5579
gopkg.in/warnings.v0 v0.1.2 // indirect
56-
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
80+
k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2 // indirect
5781
)
5882

5983
require (
@@ -71,6 +95,6 @@ require (
7195
github.com/stretchr/objx v0.5.3 // indirect
7296
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
7397
go.uber.org/atomic v1.11.0 // indirect
74-
golang.org/x/term v0.37.0 // indirect
98+
golang.org/x/term v0.40.0 // indirect
7599
gopkg.in/yaml.v3 v3.0.1 // indirect
76100
)

0 commit comments

Comments
 (0)