diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-24 00:26:05 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-24 00:26:05 +0300 |
| commit | 16113b76309dcbae1a91f8420a0bbf10863c9675 (patch) | |
| tree | 243b2db64f1a64e2f89deda6eae0f052909709dc /internal/cli/flags.go | |
| parent | e637f4fbb06b1c0661d2e77ce79d0d5149ac5c47 (diff) | |
refactor: break down large functions into smaller, focused ones
Major refactoring to improve code maintainability:
1. Split main.go (481 lines → 72 lines) into internal/cli package:
- flags.go: Command-line flag definitions and parsing
- handlers.go: General command handlers (version, config, list operations)
- sync_handlers.go: Sync-specific handlers for all sync operations
2. Refactored sync.go to extract logic into separate files:
- git_operations.go: Git command helpers (merge, push, fetch, etc.)
- repository_setup.go: Repository initialization and remote configuration
- branch_sync.go: Branch synchronization helpers
3. Reduced function sizes to meet 30-line guideline:
- syncBranch: 104 lines → 26 lines
- SyncRepository: 97 lines → 44 lines
- main(): 465 lines → 63 lines
- getAllBranches: 32 lines → 9 lines
All functionality remains the same, but the code is now more modular,
testable, and easier to understand. Each function has a single, clear
responsibility.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/cli/flags.go')
| -rw-r--r-- | internal/cli/flags.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/cli/flags.go b/internal/cli/flags.go new file mode 100644 index 0000000..c0320c5 --- /dev/null +++ b/internal/cli/flags.go @@ -0,0 +1,55 @@ +package cli + +import "flag" + +// Flags holds all command-line flag values +type Flags struct { + VersionFlag bool + ConfigPath string + ListOrgs bool + ListRepos bool + SyncRepo string + SyncAll bool + SyncCodebergPublic bool + SyncGitHubPublic bool + FullSync bool + CreateGitHubRepos bool + CreateCodebergRepos bool + DryRun bool + WorkDir string + TestGitHubToken bool +} + +// ParseFlags parses command-line flags and returns the flags struct +func ParseFlags() *Flags { + f := &Flags{} + + flag.BoolVar(&f.VersionFlag, "version", false, "print version information") + flag.BoolVar(&f.VersionFlag, "v", false, "print version information (short)") + flag.StringVar(&f.ConfigPath, "config", "", "path to configuration file") + flag.StringVar(&f.ConfigPath, "c", "", "path to configuration file (short)") + flag.BoolVar(&f.ListOrgs, "list-orgs", false, "list configured organizations") + flag.BoolVar(&f.ListRepos, "list-repos", false, "list configured repositories") + flag.StringVar(&f.SyncRepo, "sync", "", "repository name to sync") + flag.BoolVar(&f.SyncAll, "sync-all", false, "sync all configured repositories") + flag.BoolVar(&f.SyncCodebergPublic, "sync-codeberg-public", false, "sync all public Codeberg repositories to GitHub") + flag.BoolVar(&f.SyncGitHubPublic, "sync-github-public", false, "sync all public GitHub repositories to Codeberg") + flag.BoolVar(&f.FullSync, "full", false, "full bidirectional sync (enables --sync-codeberg-public --sync-github-public --create-github-repos --create-codeberg-repos)") + flag.BoolVar(&f.CreateGitHubRepos, "create-github-repos", false, "automatically create missing GitHub repositories") + flag.BoolVar(&f.CreateCodebergRepos, "create-codeberg-repos", false, "automatically create missing Codeberg repositories") + flag.BoolVar(&f.DryRun, "dry-run", false, "show what would be synced without actually syncing") + flag.StringVar(&f.WorkDir, "work-dir", ".gitsyncer-work", "working directory for cloning repositories") + flag.BoolVar(&f.TestGitHubToken, "test-github-token", false, "test GitHub token authentication") + + flag.Parse() + + // Handle --full flag by enabling all sync operations + if f.FullSync { + f.SyncCodebergPublic = true + f.SyncGitHubPublic = true + f.CreateGitHubRepos = true + f.CreateCodebergRepos = true + } + + return f +}
\ No newline at end of file |
