Skip to content

Commit 663ceeb

Browse files
committed
style: refactor function signatures and argument formatting for consistency
- Change function signatures to multi-line style for improved readability - Refactor argument passing for constructors and error handling to multi-line in TUI models and components - No logic changes, only formatting and style improvements for consistency Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent f39632f commit 663ceeb

11 files changed

Lines changed: 67 additions & 36 deletions

browser_flow.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ func exchangeCode(ctx context.Context, code, codeVerifier string) (*TokenStorage
172172
// - (storage, true, nil) on success
173173
// - (nil, false, nil) when openBrowser() fails — caller should fall back to Device Code Flow
174174
// - (nil, false, err) on a hard error (CSRF mismatch, token exchange failure, etc.)
175-
func performBrowserFlowWithUpdates(ctx context.Context, updates chan<- tui.FlowUpdate) (*tui.TokenStorage, bool, error) {
175+
func performBrowserFlowWithUpdates(
176+
ctx context.Context,
177+
updates chan<- tui.FlowUpdate,
178+
) (*tui.TokenStorage, bool, error) {
176179
updates <- tui.FlowUpdate{
177180
Type: tui.StepStart,
178181
Step: 1,
@@ -262,7 +265,6 @@ func performBrowserFlowWithUpdates(ctx context.Context, updates chan<- tui.FlowU
262265
}
263266
return exchangeCode(callbackCtx, code, pkce.Verifier)
264267
})
265-
266268
if err != nil {
267269
if errors.Is(err, ErrCallbackTimeout) {
268270
updates <- tui.FlowUpdate{

device_flow.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,10 @@ func exchangeDeviceCode(
291291

292292
// performDeviceFlowWithUpdates runs the OAuth 2.0 Device Authorization Grant
293293
// and sends progress updates through the provided channel.
294-
func performDeviceFlowWithUpdates(ctx context.Context, updates chan<- tui.FlowUpdate) (*tui.TokenStorage, error) {
294+
func performDeviceFlowWithUpdates(
295+
ctx context.Context,
296+
updates chan<- tui.FlowUpdate,
297+
) (*tui.TokenStorage, error) {
295298
config := &oauth2.Config{
296299
ClientID: clientID,
297300
Endpoint: oauth2.Endpoint{

tui/browser_model.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ func NewBrowserModel(updatesCh <-chan FlowUpdate, cancel context.CancelFunc) *Br
4343
s.Style = SpinnerStyle
4444

4545
return &BrowserModel{
46-
totalSteps: 3,
47-
stepNames: []string{"Opening browser", "Waiting for callback", "Exchanging tokens"},
48-
spinner: s,
49-
stepIndicator: components.NewStepIndicator(3, []string{"Opening browser", "Waiting for callback", "Exchanging tokens"}),
46+
totalSteps: 3,
47+
stepNames: []string{"Opening browser", "Waiting for callback", "Exchanging tokens"},
48+
spinner: s,
49+
stepIndicator: components.NewStepIndicator(
50+
3,
51+
[]string{"Opening browser", "Waiting for callback", "Exchanging tokens"},
52+
),
5053
timer: components.NewCountdownTimer(2 * time.Minute),
5154
progressBar: components.NewProgressBar(40),
5255
timeout: 2 * time.Minute,
@@ -149,7 +152,8 @@ func (m *BrowserModel) handleFlowUpdate(update FlowUpdate) tea.Cmd {
149152

150153
case StepError:
151154
m.err = fmt.Errorf("%s", update.Message)
152-
if update.Message == "Browser authorization timed out" || update.Message == "Could not open browser: exit status 1" {
155+
if update.Message == "Browser authorization timed out" ||
156+
update.Message == "Could not open browser: exit status 1" {
153157
// Fallback to device flow
154158
return func() tea.Msg {
155159
return successMsg{storage: nil, ok: false}

tui/browser_view.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ func renderBrowserComplete(m *BrowserModel) string {
7676
} else if !m.ok {
7777
// Fallback to device flow
7878
b.WriteString("\n")
79-
b.WriteString(RenderWarning("Browser flow unavailable, falling back to Device Code Flow..."))
79+
b.WriteString(
80+
RenderWarning("Browser flow unavailable, falling back to Device Code Flow..."),
81+
)
8082
b.WriteString("\n\n")
8183
} else {
8284
// Success state

tui/bubbletea_manager.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ func (m *BubbleTeaManager) ShowFlowSelection(method string) {
2828
}
2929

3030
// RunBrowserFlow executes the browser OAuth flow with an interactive TUI.
31-
func (m *BubbleTeaManager) RunBrowserFlow(ctx context.Context, perform BrowserFlowFunc) (*TokenStorage, bool, error) {
31+
func (m *BubbleTeaManager) RunBrowserFlow(
32+
ctx context.Context,
33+
perform BrowserFlowFunc,
34+
) (*TokenStorage, bool, error) {
3235
updates := make(chan FlowUpdate, 10)
3336

3437
// Create a cancellable context for the OAuth flow
@@ -83,7 +86,10 @@ func (m *BubbleTeaManager) RunBrowserFlow(ctx context.Context, perform BrowserFl
8386
}
8487

8588
// RunDeviceFlow executes the device code OAuth flow with an interactive TUI.
86-
func (m *BubbleTeaManager) RunDeviceFlow(ctx context.Context, perform DeviceFlowFunc) (*TokenStorage, error) {
89+
func (m *BubbleTeaManager) RunDeviceFlow(
90+
ctx context.Context,
91+
perform DeviceFlowFunc,
92+
) (*TokenStorage, error) {
8793
updates := make(chan FlowUpdate, 10)
8894

8995
// Create a cancellable context for the OAuth flow

tui/components/components_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@ func TestFormatPercentage(t *testing.T) {
188188
for _, tt := range tests {
189189
result := formatPercentage(tt.progress)
190190
if result != tt.expected {
191-
t.Errorf("formatPercentage(%f): expected '%s', got '%s'", tt.progress, tt.expected, result)
191+
t.Errorf(
192+
"formatPercentage(%f): expected '%s', got '%s'",
193+
tt.progress,
194+
tt.expected,
195+
result,
196+
)
192197
}
193198
}
194199
}

tui/components/timer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99

1010
// Timer displays elapsed time or countdown
1111
type Timer struct {
12-
startTime time.Time
13-
elapsed time.Duration
14-
isCountdown bool
12+
startTime time.Time
13+
elapsed time.Duration
14+
isCountdown bool
1515
totalDuration time.Duration
1616
}
1717

1818
// NewElapsedTimer creates a new elapsed time timer
1919
func NewElapsedTimer() *Timer {
2020
return &Timer{
21-
startTime: time.Now(),
21+
startTime: time.Now(),
2222
isCountdown: false,
2323
}
2424
}

tui/device_model.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ func NewDeviceModel(updatesCh <-chan FlowUpdate, cancel context.CancelFunc) *Dev
4646
s.Style = SpinnerStyle
4747

4848
return &DeviceModel{
49-
totalSteps: 2,
50-
stepNames: []string{"Requesting device code", "Waiting for authorization"},
51-
spinner: s,
52-
stepIndicator: components.NewStepIndicator(2, []string{"Requesting device code", "Waiting for authorization"}),
49+
totalSteps: 2,
50+
stepNames: []string{"Requesting device code", "Waiting for authorization"},
51+
spinner: s,
52+
stepIndicator: components.NewStepIndicator(
53+
2,
54+
[]string{"Requesting device code", "Waiting for authorization"},
55+
),
5356
timer: components.NewElapsedTimer(),
5457
infoBox: components.NewInfoBox("Device Authorization", 60),
5558
updatesCh: updatesCh,

tui/messages.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ const (
1010
StepProgress
1111
StepComplete
1212
StepError
13-
TimerTick // For countdown/elapsed time updates
14-
BrowserOpened // Browser successfully opened
15-
CallbackReceived // Callback received from browser
16-
DeviceCodeReceived // Device code received from server
17-
PollingUpdate // Polling status update
18-
BackoffChanged // Slow_down interval changed
13+
TimerTick // For countdown/elapsed time updates
14+
BrowserOpened // Browser successfully opened
15+
CallbackReceived // Callback received from browser
16+
DeviceCodeReceived // Device code received from server
17+
PollingUpdate // Polling status update
18+
BackoffChanged // Slow_down interval changed
1919
)
2020

2121
// FlowUpdate represents a progress update message from an OAuth flow.

tui/simple_manager.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ func (m *SimpleManager) ShowFlowSelection(method string) {
2828
fmt.Printf("Auth method : %s\n", method)
2929
}
3030

31-
func (m *SimpleManager) RunBrowserFlow(ctx context.Context, perform BrowserFlowFunc) (*TokenStorage, bool, error) {
31+
func (m *SimpleManager) RunBrowserFlow(
32+
ctx context.Context,
33+
perform BrowserFlowFunc,
34+
) (*TokenStorage, bool, error) {
3235
// Create a channel for updates (but we'll ignore them for simple mode)
3336
updates := make(chan FlowUpdate, 10)
3437

@@ -101,7 +104,10 @@ func (m *SimpleManager) handleBrowserUpdate(update FlowUpdate) {
101104
}
102105
}
103106

104-
func (m *SimpleManager) RunDeviceFlow(ctx context.Context, perform DeviceFlowFunc) (*TokenStorage, error) {
107+
func (m *SimpleManager) RunDeviceFlow(
108+
ctx context.Context,
109+
perform DeviceFlowFunc,
110+
) (*TokenStorage, error) {
105111
// Create a channel for updates
106112
updates := make(chan FlowUpdate, 10)
107113

0 commit comments

Comments
 (0)