Every side project starts with optimism. This one started with go mod init and a vague sense of dread.
In this series, we’ll build a real CLI tool in Go — something that actually solves a problem rather than just proving we can parse flags. We’ll use Cobra for the CLI framework and ship it with proper tests and CI.
Project Structure
// main.go
package main
import "github.com/fparch/ddd-cli/cmd"
func main() {
cmd.Execute()
}
// cmd/root.go
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "ddd",
Short: "A CLI that does things you probably don't need",
Long: `But you'll build it anyway because that's what we do.`,
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Why Cobra?
Three reasons:
- Subcommand support out of the box
- Auto-generated help and completions
- It’s what kubectl uses, and if it’s good enough for Kubernetes…
What’s Next
In Part 2, we’ll add actual commands and wire up configuration with Viper.
fparch/ddd-cli View the complete source on GitHub ↗Need help building developer tools or CLI applications? Let’s talk.
I help teams modernize legacy systems with AI-assisted development guardrails that keep the agents productive and the production safe. fitzpatricksoftware.com
