From e3be548e8d03b10c2a04d046edf49282b59d9b4c Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Thu, 25 Sep 2025 08:17:56 +0800 Subject: [PATCH] refactor(auth): replace `log` calls with `fmt` for improved consistency and standard output usage - Updated all authentication commands to use `fmt` instead of `log` for errors, info, and success messages. - Ensured message formatting aligns across commands for consistent user experience. --- internal/cmd/anthropic_login.go | 7 ++++--- internal/cmd/gemini-web_auth.go | 6 +++--- internal/cmd/login.go | 13 +++++++------ internal/cmd/openai_login.go | 7 ++++--- internal/cmd/qwen_login.go | 6 +++--- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/internal/cmd/anthropic_login.go b/internal/cmd/anthropic_login.go index d0df11fb..8e9d01cd 100644 --- a/internal/cmd/anthropic_login.go +++ b/internal/cmd/anthropic_login.go @@ -3,6 +3,7 @@ package cmd import ( "context" "errors" + "fmt" "os" "github.com/router-for-me/CLIProxyAPI/v6/internal/auth/claude" @@ -41,13 +42,13 @@ func DoClaudeLogin(cfg *config.Config, options *LoginOptions) { } return } - log.Fatalf("Claude authentication failed: %v", err) + fmt.Printf("Claude authentication failed: %v\n", err) return } if savedPath != "" { - log.Infof("Authentication saved to %s", savedPath) + fmt.Printf("Authentication saved to %s\n", savedPath) } - log.Info("Claude authentication successful!") + fmt.Println("Claude authentication successful!") } diff --git a/internal/cmd/gemini-web_auth.go b/internal/cmd/gemini-web_auth.go index 86d6e14e..f312122f 100644 --- a/internal/cmd/gemini-web_auth.go +++ b/internal/cmd/gemini-web_auth.go @@ -35,7 +35,7 @@ func DoGeminiWebAuth(cfg *config.Config) { secure1psidts = strings.TrimSpace(secure1psidts) if secure1psidts == "" { - log.Fatal("The __Secure-1PSIDTS value cannot be empty.") + fmt.Println("The __Secure-1PSIDTS value cannot be empty.") return } @@ -57,9 +57,9 @@ func DoGeminiWebAuth(cfg *config.Config) { store := sdkAuth.GetTokenStore() savedPath, err := store.Save(context.Background(), cfg, record) if err != nil { - log.Fatalf("Failed to save Gemini Web token to file: %v", err) + fmt.Printf("Failed to save Gemini Web token to file: %v\n", err) return } - log.Infof("Successfully saved Gemini Web token to: %s", savedPath) + fmt.Printf("Successfully saved Gemini Web token to: %s\n", savedPath) } diff --git a/internal/cmd/login.go b/internal/cmd/login.go index e11a62d4..dd71afe9 100644 --- a/internal/cmd/login.go +++ b/internal/cmd/login.go @@ -6,6 +6,7 @@ package cmd import ( "context" "errors" + "fmt" "github.com/router-for-me/CLIProxyAPI/v6/internal/config" sdkAuth "github.com/router-for-me/CLIProxyAPI/v6/sdk/auth" @@ -43,16 +44,16 @@ func DoLogin(cfg *config.Config, projectID string, options *LoginOptions) { if err != nil { var selectionErr *sdkAuth.ProjectSelectionError if errors.As(err, &selectionErr) { - log.Error(selectionErr.Error()) + fmt.Println(selectionErr.Error()) projects := selectionErr.ProjectsDisplay() if len(projects) > 0 { - log.Info("========================================================================") + fmt.Println("========================================================================") for _, p := range projects { - log.Infof("Project ID: %s", p.ProjectID) - log.Infof("Project Name: %s", p.Name) - log.Info("------------------------------------------------------------------------") + fmt.Printf("Project ID: %s\n", p.ProjectID) + fmt.Printf("Project Name: %s\n", p.Name) + fmt.Println("------------------------------------------------------------------------") } - log.Info("Please rerun the login command with --project_id .") + fmt.Println("Please rerun the login command with --project_id .") } return } diff --git a/internal/cmd/openai_login.go b/internal/cmd/openai_login.go index 4d292ea1..e402e476 100644 --- a/internal/cmd/openai_login.go +++ b/internal/cmd/openai_login.go @@ -3,6 +3,7 @@ package cmd import ( "context" "errors" + "fmt" "os" "github.com/router-for-me/CLIProxyAPI/v6/internal/auth/codex" @@ -52,12 +53,12 @@ func DoCodexLogin(cfg *config.Config, options *LoginOptions) { } return } - log.Fatalf("Codex authentication failed: %v", err) + fmt.Printf("Codex authentication failed: %v\n", err) return } if savedPath != "" { - log.Infof("Authentication saved to %s", savedPath) + fmt.Printf("Authentication saved to %s\n", savedPath) } - log.Info("Codex authentication successful!") + fmt.Println("Codex authentication successful!") } diff --git a/internal/cmd/qwen_login.go b/internal/cmd/qwen_login.go index bd375356..27edf408 100644 --- a/internal/cmd/qwen_login.go +++ b/internal/cmd/qwen_login.go @@ -48,13 +48,13 @@ func DoQwenLogin(cfg *config.Config, options *LoginOptions) { log.Error(emailErr.Error()) return } - log.Fatalf("Qwen authentication failed: %v", err) + fmt.Printf("Qwen authentication failed: %v\n", err) return } if savedPath != "" { - log.Infof("Authentication saved to %s", savedPath) + fmt.Printf("Authentication saved to %s\n", savedPath) } - log.Info("Qwen authentication successful!") + fmt.Println("Qwen authentication successful!") }