cmd/devtool is the central command-line utility for BrandishBot development, maintenance, and deployment. It aggregates various scripts and helpers into a single Go binary using a Command pattern and Registry, replacing scattered shell scripts.
The devtool binary is designed to be the single entry point for:
- Development tasks (building, testing, coverage)
- Database management (migrations, seeding)
- Deployment workflows (build, push, deploy, rollback)
- Runtime operations (health checks, entrypoint logic)
Most Makefile targets delegate to this tool under the hood.
go run ./cmd/devtool <command> [flags]Or via make:
make migrate-up # Runs: go run ./cmd/devtool migrate upbuild: Compilescmd/appandcmd/discordintobin/appandbin/discord_bot. Injects build metadata (Version, BuildTime, GitCommit) via ldflags.check-coverage: Runs tests with coverage, generates HTML reports, and verifies coverage thresholds.- Flags:
-file <path>: Check coverage for a specific file.-threshold <int>: Set minimum coverage percentage (default 80).-html: Generatecoverage.html.-watch: Watch for file changes and re-run tests automatically (usesfsnotify).-smart: Only run tests for changed packages and their dependents (usespackage_selector.go).
- Flags:
check-deps: Verifies that required system dependencies (Go, Docker, etc.) are installed.bench: Runs benchmarks.
migrate: Manages database migrations.up: Apply all pending migrations.down: Rollback the last migration.status: Show migration status.create: Create a new migration file.
check-db: Checks if the database is reachable.wait-for-db: Blocks until the database is ready (useful in CI/CD or startup scripts).test-migrations: Verifies migration idempotency (up/down cycles).
deploy: Orchestrates the deployment process.rollback: Rolls back to a previous version.push: Pushes build artifacts to the registry.
entrypoint: Replaces the legacydocker-entrypoint.sh. Handles:- Setting
DB_HOSTto "db" if missing (for Docker Compose compatibility). - Database readiness checks.
- Conditional backups and migrations on startup.
- Starting the application.
- Setting
health-check: Performs a health check against the running service.doctor: Diagnoses common environment issues.
The tool uses a Command Registry pattern. Commands are registered in cmd/devtool/main.go and implemented in separate files within cmd/devtool/. This allows for easy extensibility and shared logic (like logging or configuration loading) across all commands.
- Package Selector (
package_selector.go): Centralized logic for determining which packages to test based on git changes (-smartmode) or explicit selection. - File Watcher (
fsnotify): Recursive file watching for the-watchflag, enabling rapid test feedback loops. - UI Helpers (
ui.go): Cross-platform utilities, such asOpenBrowser(usingxdg-open,open, orstart) for opening coverage reports. - Strict Flags: Commands use strict flag parsing to prevent ambiguous behavior.
The scripts/ directory has been removed. All ad-hoc utility scripts (e.g., debug tools, one-off fixes) are now consolidated into cmd/devtool commands to leverage the shared Go environment and type safety.