How marcellodesales/cloner works
Project type and purpose
• Type: Standalone CLI application (open-source tool) written in Go.
• Purpose: Accepts a git-URL (HTTPS or SSH), reads optional YAML config, and clones into a predictable directory tree ($CLONE_BASE/host/org/repo), supporting idempotence and a force-overwrite flag.
File structure
• Top-level packages
• cmd/ – Cobra commands (CLI entrypoints: root, local)
• api/ – Service layer abstractions (git_service, git_controller, git_type)
• config/ – Viper-backed YAML configuration loader
• util/ – Low-level utilities (filesystem, logging, regex, dirs)
• main.go – application bootstrap
• Supporting files
• Dockerfiles & docker-compose.yaml – containerization
• CI workflows (.github/workflows) – build, lint, test, release
• Makefile – build/test/release commands
README for architectural clues
• Provided ASCII overview:
• main +-> CMD +----->+ API +----->+ UTIL |
• ^ |
• v
• > CONFIG
• Key frameworks: Cobra (CLI), Viper (config), Go modules
Main components & interactions
a. Components
• User / Shell
• main (bootstrap)
• CMD (Cobra commands package)
• CONFIG (Viper loader)
• API (git service abstractions)
• UTIL (filesystem, logging, SSH)
• External Systems:
• File System (for directory creation, deletion)
• Git Hosts / Network (SSH/HTTPS)
b. Data flow
1. User invokes cloner local --repo URL [--force] [--privateKey ...]
2. main initializes logger, root command, and loads global flags
3. CMD reads flags, calls CONFIG to load ~/.cloner.yaml
4. CMD invokes appropriate API service (git clone)
5. API calls UTIL functions to:
• parse URL and derive host/org/repo
• create directories
• invoke external git clone process (with SSH key or HTTPS)
6. UTIL logs progress, returns status to API → CMD → main → User
c. Architectural patterns / principles
• Separation of concerns:
• CLI logic (parsing, help) isolated in cmd/
• Business logic in api/
• Configuration in config/
• Side-effecting operations in util/
• Dependency injection via function parameters rather than global state
• Idempotency: clone operation checks for existing paths
d. Key technologies
• Go modules, Cobra, Viper, standard library (os/exec, filepath), Docker for packaging, Git CLI