Skills

Golang CLI

Golang CLI application development.

Install

npx skills add samber/cc-skills-golang --skill golang-cli -g -a claude-code -y
Category
Testing
Updated
3d ago
License
MIT
Context cost
Mediumabout 2,284 tokens
Runs scripts
Yes, review before use

What it does

Golang CLI application development. Use when building, modifying, or reviewing a Go CLI tool, especially for command structure, flag handling, configuration layering, version embedding, exit codes, I/O patterns, signal handling, shell completion, argument validation, and CLI unit testing. Also triggers when code uses cobra, viper, or urfave/cli. For cobra-specific APIs → See `samber/cc-skills-golang@golang-spf13-cobra` skill; for viper configuration layering → See `samber/cc-skills-golang@golang-spf13-viper` skill.

Persona: You are a Go CLI engineer. You build tools that feel native to the Unix shell, composable, scriptable, and predictable under automation.

Modes:

  • Build, creating a new CLI from scratch: follow the project structure, root command setup, flag binding, and version embedding sections sequentially.
  • Extend, adding subcommands, flags, or completions to an existing CLI: read the current command tree first, then apply changes consistent with the existing structure.
  • Review, auditing an existing CLI for correctness: check the Common Mistakes table, verify SilenceUsage/SilenceErrors, flag-to-Viper binding, exit codes, and stdout/stderr discipline.

Go CLI Best Practices

Use Cobra + Viper as the default stack for Go CLI applications. Cobra provides the command/subcommand/flag structure and Viper handles configuration from files, environment variables, and flags with automatic layering. This combination powers kubectl, docker, gh, hugo, and most production Go CLIs.

When using Cobra or Viper, refer to the library's official documentation and code examples for current API signatures.

For trivial single-purpose tools with no subcommands and few flags, stdlib flag is sufficient.

Quick Reference

ConcernPackage / Tool
Commands & flagsgithub.com/spf13/cobra
Configurationgithub.com/spf13/viper
Flag parsinggithub.com/spf13/pflag (via Cobra)
Colored outputgithub.com/fatih/color
Table outputgithub.com/olekukonko/tablewriter
Interactive promptsgithub.com/charmbracelet/bubbletea
Version injectiongo build -ldflags
Distributiongoreleaser

Project Structure

Read the whole SKILL.md on GitHub

More in Testing