Skip to content

Commit 9583f6b

Browse files
author
Mansi
committed
refactor: extract setKiroIncognitoMode helper to reduce code duplication
- Added setKiroIncognitoMode() helper function to handle Kiro auth incognito mode setting - Replaced 3 duplicate code blocks (21 lines) with single function calls (3 lines) - Kiro auth defaults to incognito mode for multi-account support - Users can override with --incognito or --no-incognito flags This addresses the code duplication noted in PR #1 review.
1 parent 02d8a1c commit 9583f6b

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

cmd/server/main.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ func init() {
4747
buildinfo.BuildDate = BuildDate
4848
}
4949

50+
// setKiroIncognitoMode sets the incognito browser mode for Kiro authentication.
51+
// Kiro defaults to incognito mode for multi-account support.
52+
// Users can explicitly override with --incognito or --no-incognito flags.
53+
func setKiroIncognitoMode(cfg *config.Config, useIncognito, noIncognito bool) {
54+
if useIncognito {
55+
cfg.IncognitoBrowser = true
56+
} else if noIncognito {
57+
cfg.IncognitoBrowser = false
58+
} else {
59+
cfg.IncognitoBrowser = true // Kiro default
60+
}
61+
}
62+
5063
// main is the entry point of the application.
5164
// It parses command-line flags, loads configuration, and starts the appropriate
5265
// service based on the provided flags (login, codex-login, or server mode).
@@ -465,36 +478,18 @@ func main() {
465478
// Users can explicitly override with --no-incognito
466479
// Note: This config mutation is safe - auth commands exit after completion
467480
// and don't share config with StartService (which is in the else branch)
468-
if useIncognito {
469-
cfg.IncognitoBrowser = true
470-
} else if noIncognito {
471-
cfg.IncognitoBrowser = false
472-
} else {
473-
cfg.IncognitoBrowser = true // Kiro default
474-
}
481+
setKiroIncognitoMode(cfg, useIncognito, noIncognito)
475482
cmd.DoKiroLogin(cfg, options)
476483
} else if kiroGoogleLogin {
477484
// For Kiro auth, default to incognito mode for multi-account support
478485
// Users can explicitly override with --no-incognito
479486
// Note: This config mutation is safe - auth commands exit after completion
480-
if useIncognito {
481-
cfg.IncognitoBrowser = true
482-
} else if noIncognito {
483-
cfg.IncognitoBrowser = false
484-
} else {
485-
cfg.IncognitoBrowser = true // Kiro default
486-
}
487+
setKiroIncognitoMode(cfg, useIncognito, noIncognito)
487488
cmd.DoKiroGoogleLogin(cfg, options)
488489
} else if kiroAWSLogin {
489490
// For Kiro auth, default to incognito mode for multi-account support
490491
// Users can explicitly override with --no-incognito
491-
if useIncognito {
492-
cfg.IncognitoBrowser = true
493-
} else if noIncognito {
494-
cfg.IncognitoBrowser = false
495-
} else {
496-
cfg.IncognitoBrowser = true // Kiro default
497-
}
492+
setKiroIncognitoMode(cfg, useIncognito, noIncognito)
498493
cmd.DoKiroAWSLogin(cfg, options)
499494
} else if kiroImport {
500495
cmd.DoKiroImport(cfg, options)

0 commit comments

Comments
 (0)