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.
This commit is contained in:
Luis Pater
2025-09-25 08:17:56 +08:00
parent 2724630430
commit e3be548e8d
5 changed files with 21 additions and 18 deletions

View File

@@ -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!")
}

View File

@@ -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)
}

View File

@@ -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 <project_id>.")
fmt.Println("Please rerun the login command with --project_id <project_id>.")
}
return
}

View File

@@ -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!")
}

View File

@@ -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!")
}