summaryrefslogtreecommitdiff
path: root/internal/cli
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-24 10:00:28 +0300
committerPaul Buetow <paul@buetow.org>2025-06-24 10:00:28 +0300
commitaf8ab19f5def6f00081b0a6d1e5b20b76683f720 (patch)
tree89ab045f8da4af0bb6af8b26e7851e7bddfad6e7 /internal/cli
parent577d3d37a47dc7279d7e56975448aa330d6b5469 (diff)
refactor: use value semantics for GitHub and Codeberg clients
- Changed github.NewClient() to return Client instead of *Client - Changed codeberg.NewClient() to return Client instead of *Client - Updated sync_handlers.go to handle value semantics properly - Both clients only contain immutable string fields, making value semantics more appropriate docs: add comprehensive documentation - Added doc/ directory with full documentation - Created architecture overview explaining system design - Added complete API reference for all packages, types, and functions - Created configuration guide with examples - Added usage examples and common workflows - Created development guide for contributors - Updated README with links to documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/cli')
-rw-r--r--internal/cli/sync_handlers.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/internal/cli/sync_handlers.go b/internal/cli/sync_handlers.go
index dd0dcf9..4fbb6cf 100644
--- a/internal/cli/sync_handlers.go
+++ b/internal/cli/sync_handlers.go
@@ -37,9 +37,13 @@ func HandleSyncAll(cfg *config.Config, flags *Flags) int {
}
// Initialize GitHub client if needed
- var githubClient *github.Client
+ var githubClient github.Client
+ var hasGithubClient bool
if flags.CreateGitHubRepos {
- githubClient = initGitHubClient(cfg)
+ if client := initGitHubClient(cfg); client != nil {
+ githubClient = *client
+ hasGithubClient = true
+ }
}
syncer := sync.New(cfg, flags.WorkDir)
@@ -49,8 +53,8 @@ func HandleSyncAll(cfg *config.Config, flags *Flags) int {
fmt.Printf("\n[%d/%d] Syncing %s...\n", i+1, len(cfg.Repositories), repo)
// Create GitHub repo if needed
- if githubClient != nil {
- if err := createRepoWithClient(githubClient, repo, fmt.Sprintf("Mirror of %s", repo)); err != nil {
+ if hasGithubClient {
+ if err := createRepoWithClient(&githubClient, repo, fmt.Sprintf("Mirror of %s", repo)); err != nil {
fmt.Printf("ERROR: Failed to create GitHub repo %s: %v\n", repo, err)
fmt.Printf("Stopping sync due to error.\n")
return 1
@@ -207,7 +211,7 @@ func initGitHubClient(cfg *config.Config) *github.Client {
}
fmt.Println("GitHub client initialized successfully with token")
- return githubClient
+ return &githubClient
}
func createRepoWithClient(client *github.Client, repoName, description string) error {
@@ -230,9 +234,13 @@ func printFullSyncSeparator() {
func syncCodebergRepos(cfg *config.Config, flags *Flags, repos []codeberg.Repository, repoNames []string) int {
// Initialize GitHub client if needed
- var githubClient *github.Client
+ var githubClient github.Client
+ var hasGithubClient bool
if flags.CreateGitHubRepos {
- githubClient = initGitHubClient(cfg)
+ if client := initGitHubClient(cfg); client != nil {
+ githubClient = *client
+ hasGithubClient = true
+ }
}
fmt.Printf("\nStarting sync of %d repositories...\n", len(repoNames))
@@ -250,7 +258,7 @@ func syncCodebergRepos(cfg *config.Config, flags *Flags, repos []codeberg.Reposi
fmt.Printf("\n[%d/%d] Syncing %s...\n", i+1, len(repoNames), repoName)
// Create GitHub repo if needed
- if githubClient != nil && flags.CreateGitHubRepos {
+ if hasGithubClient && flags.CreateGitHubRepos {
codebergRepo := repoMap[repoName]
description := codebergRepo.Description
if description == "" {