How mshddev/sonacli works
1. What this repo is
- sonacli is a Go-based command-line client for SonarQube Community Build only.
- It runs locally on Linux and macOS and talks to a remote SonarQube server over HTTP.
2. Top-level runtime shape
- The binary entrypoint is main.go.
- internal/cli is the primary presentation layer: it defines the root command and subcommands, parses flags/args, and routes execution.
- The command surface is organized around auth, issue, project, star, skill, update, and version.
3. Configuration and auth boundary
- internal/config owns local persisted settings, especially the SonarQube server URL and user token established by sonacli auth setup.
- auth status reads that local state back out, so the boundary is: user machine state in config, SonarQube credentials only used to reach the server.
- This makes authentication a local bootstrap step rather than a long-lived service.
4. SonarQube API integration
- internal/sonarqube/client.go is the HTTP client layer for SonarQube.
- All server-facing features flow through this client: project listing, issue listing/showing, starring/un-starring, and any metadata lookups needed by the CLI.
- The architectural boundary is clear: internal/cli handles UX and argument normalization; internal/sonarqube handles remote API calls and response handling.
5. Issue and project workflows
- issue and project commands are the main read paths for consuming analysis results.
- The CLI supports both direct issue keys and SonarQube issue URLs, so command handlers likely include parsing/normalization before calling the API client.
- The --pretty style output in the README suggests formatting concerns are kept in the CLI layer rather than in the API client.
6. Star operations
- internal/cli/star.go plus the SonarQube client provide a small mutation workflow for starring projects.
- This is a separate command family from read-only listing, but it uses the same server/auth/config plumbing.
7. Skill packaging subsystem
- internal/agentskill is a distinct subsystem for installing and uninstalling a packaged “skill” bundle.
- The bundle is stored under internal/agentskill/assets, including SKILL.md and agent configuration such as agents/openai.yaml.
- Architecturally, this is a filesystem distribution feature: the CLI ships assets with the binary and manages their placement on the user’s machine.
8. Self-update and release distribution
- internal/selfupdate updates the installed binary in place by fetching a newer GitHub release.
- The separate install.sh bootstrap script downloads the correct release archive for the user’s OS/CPU, verifies checksums.txt, and installs the binary.
- That creates two related but distinct delivery paths: initial install via GitHub Releases, then in-app update via the updater subsystem.
9. Documentation and demo/sample data
- docs/ contains the command reference and a demo script/tape for showcasing flows.
- docs/_demo-source and tests/fixtures/sample-basic are synthetic Go projects with sonar-project.properties, used to generate predictable SonarQube analysis data for demos and tests.
- These directories are not runtime dependencies; they support documentation and reproducible examples.
10. Testing and quality gates
- The repo mixes Go unit tests (*_test.go) with scenario-style markdown tests under tests/.
- tests/bin, tests/results, and tests/fixtures indicate a harness that exercises the CLI end-to-end against controlled inputs and captures output.
- This is important architecturally because the CLI behavior is driven by command output formatting, URL parsing, and remote API interactions.
11. Build, CI, and release pipeline
- Makefile and GitHub Actions workflows (ci.yml, release.yml) orchestrate builds, tests, and releases.
- Release artifacts are likely version-stamped from Git tags or git describe, matching the README’s note about make build.
- The release pipeline matters because both the installer and self-update features depend on consistent GitHub release artifacts and checksums.
Main entry points: root.go Root cmd · client.go API client · config.go Config · README.md Scenario tests
Components 18
CLI Runtime
Command parsing and user-facing execution
- main · CLI binary entrypoint
main.go - Root cmd · Top-level command wiring
internal/cli/root.go - Auth · Local server-token setup and status
internal/cli/auth.go - Issue · Issue lookup and listing flows
internal/cli/issue.go - Project · Project listing and related views
internal/cli/project.go - Star · Project starring actions
internal/cli/star.go - Skill · Skill install and uninstall UX
internal/cli/skill.go - Update · In-app self-update command
internal/cli/update.go - Version · Build and release version display
internal/cli/version.go
SonarQube Integration
Remote API access and server workflows
- API client · SonarQube server API wrapper
internal/sonarqube/client.go
Delivery
Install, update, and packaged skill assets
- Config · Persisted server URL and token
internal/config/config.go - Skill mgr · Installs packaged agent skill assets
internal/agentskill/manager.go - Skill assets · Embedded SKILL.md and agent config
internal/agentskill/assets.go - Updater · Fetches and installs newer release binaries
internal/selfupdate/updater.go - Install script · Downloads release archive and verifies checksums
install.sh
Support
Docs, samples, and release tooling
- Docs · Command reference and demo tape
docs/cli.md - Sample app · Synthetic Go project for demos and tests
docs/_demo-source/src/auth.go - Scenario tests · Markdown scenarios and captured outputs
tests/README.md
Connections 23
- main → Root cmd: starts · Binary initializes the command tree
- Root cmd → Auth: subcommand · Routes auth commands
- Root cmd → Issue: subcommand · Routes issue commands
- Root cmd → Project: subcommand · Routes project commands
- Root cmd → Star: subcommand · Routes starring commands
- Root cmd → Skill: subcommand · Routes skill management commands
- Root cmd → Update: subcommand · Routes update commands
- Root cmd → Version: subcommand · Routes version command
- Auth → Config: reads/writes · Persists and loads local SonarQube connection state
- Issue → Config: reads · Uses stored credentials for server access
- Project → Config: reads · Uses stored credentials for server access
- Star → Config: reads · Uses stored credentials for server access
- Issue → API client: calls · Fetches issues and resolves issue references
- Project → API client: calls · Fetches project data
- Star → API client: calls · Stars and unstars projects
- Skill → Skill mgr: uses · Installs or removes the skill bundle
- Skill mgr → Skill assets: reads · Uses embedded files as the install source
- Update → Updater: uses · Triggers in-place binary update
- Install script → Updater: complements · Initial install and in-app update form one delivery path
- Docs → Sample app: demonstrates · Docs and demo flows use a synthetic project
- Scenario tests → Root cmd: exercises · Scenario tests validate command behavior
- Scenario tests → API client: exercises · End-to-end tests cover remote API-driven flows
- Scenario tests → Install script: exercises · Install-script scenario coverage