Watermarked preview · swipe or use ← →
One Binary, Ships Anywhere
Go for Command-Line Tools
One Binary, Ships Anywhere · Book Three of the Go for Absolute Beginners Series
kubectl. terraform. gh. rclone. hugo. The tools developers rely on most — the ones they install once and never think about again — are almost all written in Go. There is a reason. Go produces statically linked binaries that start in milliseconds, require no runtime, cross-compile for any platform from a single machine, and ship as a single file. When you need a tool that people can actually install and trust, Go is the right choice.
Go for Command-Line Tools teaches you how to build exactly that kind of tool. The book follows taskctl — a command-line client for the task API from Books One and Two — from a ten-line main function to a polished, distributable CLI with subcommands, persistent flags, shell completion for bash, zsh, and fish, layered configuration, concurrent execution with a worker pool, and fully automated release distribution through GoReleaser.
Part I — Foundations. Go's standard flag package for simple CLIs. cobra for real subcommand trees with persistent and local flag inheritance. Viper for layered configuration where command-line flags override environment variables override config files override defaults, with no boilerplate. Build-time version injection with ldflags so every binary knows its own version and commit SHA.
Part II — Input and Output. Reading and writing configuration files with proper OS-specific paths on Linux, macOS, and Windows. Walking directory trees and manipulating file paths safely. Making authenticated HTTP requests with timeouts, retry logic, and structured error handling. Calling external processes with exec.Command, capturing stdout and stderr, handling signals, and knowing when a subprocess should inherit the parent terminal.
Part III — Real Work. Running operations concurrently with a bounded worker pool that reports progress live. Writing output in plain text, JSON, and table formats with a single flag switch. Error messages that tell the user what went wrong and what to do about it, rather than dumping a stack trace or silently returning exit code 1.
Part IV — Ship It. Testing CLIs by capturing stdout and stderr, simulating user input, and running integration tests against a real server. Cross-compiling for every target with a single make command. Generating shell completion scripts automatically from cobra. Releasing with GoReleaser to produce checksummed archives, a Homebrew formula, and a GitHub Release — all from one configuration file.
The difference between a script that you use and a tool that other people use is craft. This book teaches you the craft.
ISBN: 978-8-19216-300-9 · Pages: 329 · Edition: First, 2026
Level: Requires beginner-level Go familiarity. No prior CLI development or DevOps background required.
No reviews yet — be the first to share your thoughts.
Share your experience with this book. Reviews are moderated before publication to keep discussions useful and respectful.