A comprehensive Go CLI application template with modern tooling, automated testing, releases, and documentation.
- Modern CLI Framework: Built with Cobra
- Comprehensive Testing: Unit tests with coverage reporting
- Code Quality: Integrated linting with golangci-lint
- Automated Releases: Cross-platform builds with GoReleaser
- GitHub Actions: CI/CD pipelines for testing, building, and deploying
- Documentation: MkDocs with Material theme, auto-deployed to GitHub Pages
- Cross-Platform: Builds for Linux, macOS, and Windows (amd64/arm64)
- Container Support: Docker images and Kubernetes deployment examples
- Package Distribution: Homebrew tap and GitHub Container Registry
# Install the CLI
go install github.com/mavogel/cli-template@latest
# Try it out
cli-template hello
cli-template hello --name "Developer"
cli-template --version
go install github.com/mavogel/cli-template@latest
brew tap mavogel/homebrew-tap
brew install cli-template
Download the latest release from GitHub Releases.
docker run --rm ghcr.io/mavogel/cli-template:latest --help
Install the required tools using Homebrew:
# Install Go (if not already installed)
brew install go
# Install development tools
brew install golangci-lint
brew install goreleaser
# Install Docker for documentation (MkDocs)
# Download from https://docker.com/products/docker-desktop
# Or install via Homebrew Cask:
brew install --cask docker
# Clone the repository
git clone https://github.com/mavogel/cli-template.git
cd cli-template
# Install Go dependencies
go mod download
# Verify setup
make all
# Run tests
make test
# Build the application
make build
# Serve documentation locally
make docs-serve
Tool | Purpose | Installation |
---|---|---|
Go | Programming language | brew install go |
golangci-lint | Code linting | brew install golangci-lint |
GoReleaser | Release automation | brew install goreleaser |
Docker | Documentation (MkDocs) | brew install --cask docker |
Make | Build automation | Usually pre-installed |
# Show help
cli-template --help
# Show version
cli-template --version
# Hello command
cli-template hello
cli-template hello --name "Alice"
cli-template hello -n "Bob"
# Generate shell completions
cli-template completion bash > /usr/local/etc/bash_completion.d/cli-template
cli-template completion zsh > "${fpath[1]}/_cli-template"
The CLI looks for configuration files in:
./cli-template.yaml
(current directory)~/.cli-template.yaml
(home directory)/etc/cli-template/config.yaml
(system)
Example configuration:
log_level: info
output_format: text
hello:
default_name: "World"
cli-template/
βββ .github/
β βββ workflows/ # GitHub Actions CI/CD
βββ cmd/ # Command implementations
β βββ root.go # Root command
β βββ hello.go # Example subcommand
β βββ *_test.go # Command tests
βββ docs/ # Documentation source
βββ dist/ # Build artifacts (generated)
βββ bin/ # Local build output
βββ .golangci.yml # Linting configuration
βββ .goreleaser.yaml # Release configuration
βββ Dockerfile # Container build
βββ Makefile # Build automation
βββ mkdocs.yml # Documentation config
βββ go.mod # Go module
βββ main.go # Application entry point
make help # Show all available targets
make build # Build the binary
make test # Run tests
make test-coverage # Run tests with coverage
make lint # Run linting
make lint-fix # Run linting with auto-fix
make clean # Clean build artifacts
make deps # Download dependencies
make run # Run the application
make all # Run all checks and build
# Release
make release-check # Validate GoReleaser config
make release-snapshot # Create snapshot build
make release # Create release (requires tag)
# Documentation (requires Docker)
make docs-serve # Serve docs locally at http://localhost:8000
make docs-build # Build documentation
make docs # Build and validate docs
# Run all tests
make test
# Run with coverage
make test-coverage
open coverage.html
# Run specific tests
go test ./cmd -run TestHelloCommand
# Benchmark tests
go test -bench=. ./...
# Run all linters
make lint
# Auto-fix issues where possible
make lint-fix
# Run specific linter
golangci-lint run --enable-only=errcheck
# Local build
make build
# Cross-platform snapshot
make release-snapshot
# Check built artifacts
ls -la dist/
# Serve locally using Docker (http://localhost:8000)
make docs-serve
# Build documentation using Docker
make docs-build
# View built docs
open site/index.html
-
Create and push a tag:
git tag v1.0.0 git push origin v1.0.0
-
GitHub Actions automatically:
- Builds cross-platform binaries
- Creates GitHub release
- Publishes Docker images
- Updates Homebrew tap
# Test release configuration
make release-check
# Create snapshot (no publishing)
make release-snapshot
# Check artifacts
ls -la dist/
- Create
cmd/newcommand.go
:
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var newCmd = &cobra.Command{
Use: "new",
Short: "Description of new command",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("New command executed!")
},
}
func init() {
rootCmd.AddCommand(newCmd)
}
- Add tests in
cmd/newcommand_test.go
- Update documentation
- Update
go.mod
with your module name - Replace
mavogel/cli-template
in all files - Update
.goreleaser.yaml
repository settings - Modify
mkdocs.yml
site information - Update GitHub Actions repository references
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes and add tests
- Run tests and linting:
make all
- Commit with conventional commits:
git commit -m "feat: add amazing feature"
- Push and create a Pull Request
Full documentation is available at https://mavogel.github.io/cli-template/
- Bug Reports: GitHub Issues
- Feature Requests: GitHub Issues
- Questions: GitHub Discussions
This project is licensed under the MIT License - see the LICENSE file for details.
- Cobra - Powerful CLI framework
- GoReleaser - Release automation
- golangci-lint - Go linting
- MkDocs Material - Documentation theme
Made with β€οΈ for the Go community